There's no direct way to look at a filesystem entry and get your effective permissions on it. And computing the effective permission set on a file or directory is...complicated (that would be a polite way of putting it).
Seems like that would be a fairly obvious piece of information that the System.IO classes ought to provide, but evidently the CLR team didn't think so. I think part of the problem is the inherent race condition. The permissions on a given object are dynamic and could conceivably change at any time. They could even change between your permissions check and the actual accessing of the object, resulting in an exception being raised.
These questions have some help:
The easiest way is to demand the permissions you want, catch the exception if you don't have them and use that to return a bool yes/no value:
// you'll need access to the namespace namespace System.Security.Permissions
public bool HasAccess( string path , FileIOPermissionAccess accessDesired )
{
bool isGranted ;
try
{
FileIOPermission permission = new FileIOPermission( accessDesired , path ) ;
permission.Demand() ;
isGranted = true ;
}
catch
{
isGranted = false ;
}
return isGranted ;
}