locked
Quick way to tell if user has access to a directory? RRS feed

  • Question

  • While performing IO operations its useful to be able to give users more direct feedback as to why the application can not perform a particular task.

    Is there any way to check if the user has access to a network, or folder path? Many times their Windows Credentials are not saved. Sometimes They just don't have write privileges.

    It takes a long time before the system even spits back an error when trying to create a file when users don't have access to the path, or writes to a file. Then I have to give some feedback like, "Check if you have access to the folder, check if the file is already open, check if the computer on the network is turned on.." etc.

    Particularly, its rather inconvenient when the file save/delete must be the final step at the end of a bunch of code. Especially when that code performs prep work that effects performance before finding out the user can't writing or deleting a file.

    Is there a good way to perform 1 - Folder access, and 2 - file access, of users before letting my code continue? I'm mostly concerned with Local directories("C:\foldername"), and Network directories like ("\\computername\foldername").

    Feedback aside, just as a developer, it would be useful for me to be able to check for these issues before my code executes.

    Thanks!
    Thursday, September 8, 2016 9:38 PM

Answers

  • Unless you want to delve in the vagaries of ACL = Access Control List which is where Windows stores folder and file permissions, creating and deleting a temp file is the easiest way.

    It typically does not take much time if the permission is granted, which should be the majority of cases anyway.


    -Tom. Microsoft Access MVP

    • Proposed as answer by Chenchen Li Friday, September 9, 2016 7:56 AM
    • Marked as answer by HTHP Monday, September 12, 2016 8:02 PM
    Thursday, September 8, 2016 10:49 PM

All replies

  • Unless you want to delve in the vagaries of ACL = Access Control List which is where Windows stores folder and file permissions, creating and deleting a temp file is the easiest way.

    It typically does not take much time if the permission is granted, which should be the majority of cases anyway.


    -Tom. Microsoft Access MVP

    • Proposed as answer by Chenchen Li Friday, September 9, 2016 7:56 AM
    • Marked as answer by HTHP Monday, September 12, 2016 8:02 PM
    Thursday, September 8, 2016 10:49 PM
  • Although I had put some code together some time ago to get permissions on a folder for this exact scenario, in the end I'm with Tom on this one.  The simplest solution is to try a create a text file, try to modify if (and save), try and delete it and trap for errors to report back the status of permissions.

    -- Daniel Pineault, 2010-2015 Microsoft MVP Professional Support: http://www.cardaconsultants.com MS Access Tips and Code Samples: http://www.devhut.net

    Friday, September 9, 2016 12:37 AM
  • Okay, thanks for the advice!
    Monday, September 12, 2016 8:03 PM