Click here to Skip to main content
15,918,808 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am using .net 2.0 to build a windows form application in C#.
I have a DirectoryInfo instance associated with a directory. Can any one tell me how can I know:-
1. Whether my application read access to the directory.
2. Whether my application have write access to the directory.
Is there any method\Property available for doing this task? If so, let me know.
Thanks in advance.
Posted

There is no a managed way to acquire file/directory permissions (Access Control List), according to this http://bytes.com/topic/c-sharp/answers/259010-reading-file-permissions[^]. You can do this via Windows API and P/Invoke.

See also this, a useful set of related codelets: http://www.java2s.com/Tutorial/CSharp/0300__File-Directory-Stream/0240__File-Permission.htm[^].

Permission is not the only reason for inaccessible files.

However, do you really need to get into this sophisticated stuff? I have my own practical non-nonsense approach to this. I do access under try-catch block, catch access exception and process it the way I want. It is very practical, because it's very hard to do all checks. This is exactly what structured exceptions are design for. As access to a new file system object does not happen often, there is no performance hit.

—SA
 
Share this answer
 
Comments
Olivier Levrey 10-Mar-11 4:44am    
Best answer here. An easy and efficient workaround that I use as well. A 5.
Sergey Alexandrovich Kryukov 10-Mar-11 5:14am    
I knew you would understand this.
Thank you, Olivier.
--SA
Olivier Levrey 10-Mar-11 5:25am    
You are welcome.
This question was posted here[^] by someone else. Hope the answer helps you!
 
Share this answer
 
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900