You need to use the Security
namespace.
See this SO answer.
From the answers:
FileIOPermission writePermission = new FileIOPermission(FileIOPermissionAccess.Write, filename);
if(!SecurityManager.IsGranted(writePermission))
{
//No permission.
//Either throw an exception so this can be handled by a calling function
//or inform the user that they do not have permission to write to the folder and return.
}
Update: (following comments)
FileIOPermission
deals with security policies not filesystem permissions, so you need to use DirectoryInfo.GetAccessControl
.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…