Any way to check if write permissions are available on a given path that could be either a local folder (c:\temp) or a UNC (\server\share)? I can't use try/catch because I might have write permissions but not delete so I wouldn't be able to delete created file...
Yes you can use the FileIOPermission
class and the FileIOPermissionAccess
enum.
FileIOPermissionAccess.Write
:
Access to write to or delete a file or directory. Write access includes deleting and overwriting files or directories.
FileIOPermission f = new FileIOPermission(FileIOPermissionAccess.Write, myPath);
try
{
f.Demand();
//permission to write/delete/overwrite
}
catch (SecurityException s)
{
//there is no permission to write/delete/overwrite
}