I use simple practical approach in this case. It's called
offensive programming as opposed to
defensive programming.
Here is what you do. Suppose you need the write access to the folder to write a file. Do the following:
bool CanCreateFile(string fileName) {
try {
System.IO.StreamWriter writer =
new System.IO.StreamWriter(fileName, false);
if (writer != null) writer.Close();
return true;
catch { return false; }
}
Using this idea, you can do a more fine-grain check to see if the file is already exist, which also can show the lack of read access. When you do the check, you show something like "Access denied" to the user anyway, right? In real life, think if you need this check at all. I never do it, I just try to read or write and create file and deal with exception. In this case, I show sufficient and accurate exception information to the user. This is safer (no exceptions hidden by catching them prematurely and blocking their propagation), simpler and more robust.
—SA