0

I know that this method is good to check if a user has write permissions to folder:

Directory.GetAccessControl(path);

If it throws UnauthorizedAccessException I know that the user has read permission or non permission.

How to know if a user has read permissions?

Is Directory.Exists(path) a good enough solution?

Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343
user3364652
  • 480
  • 8
  • 23
  • 1
    Please check the following link http://stackoverflow.com/questions/11709862/check-if-directory-is-accessible-in-c – Hemi81 Dec 06 '16 at 13:10
  • 1
    Directory.GetAccessControl(path) will throw exception in the user hasn't write permissions. – user3364652 Dec 06 '16 at 13:14
  • @programmer117 's solution is the best possible as I think - you should suggest making it a small seperate answer cause I think this is not trivial, or just Close the issue ;) BTW: "According to MSDN, Directory.Exists should return false if you don't have read access to the Directory" - so yes to your original question, the problem will be you can't be sure if the folder does even exists by just checking it like this – TripleEEE Dec 06 '16 at 13:22
  • 1
    According to official documentation, Directory.GetAccessControl(path) will throw exception if user doesn't have write permissions to folder, so it isn't looks like a good solution to test read permissions – user3364652 Dec 06 '16 at 13:46

0 Answers0