Quick way to tell if you can write a file in C#

31. July 2012 11:03 by Mrojas in   //  Tags: ,   //   Comments (0)

So a quick way to determine if you can write a file, which can use even from the debugger is to use something like:

 

System.IO.Directory.GetAccessControl(@"<filename>").GetAccessRules(true,true,typeof(System.Security.Principal.SecurityIdentifier))
 
This will return a list of access rules and you can examine them.
For each rule Check the AccessControlType==AccessControlType.Allow and not AccessControlType.Deny