I am currently writing an application that needs to examine the current user's permission for a file in the Windows file system given the file path. The application is written in C# .Net 4.0. I believe I am "in the right area", but am in need of help "driving it home". This question is in the right ballpark:Iterate through permissions on a file in the windows file system in C#, but is more concerned with multiple users - I am concerned with the current user.
Here is what I have so far:
FileSecurity fsObj = file.GetAccessControl(AccessControlSections.Access);
foreach (FileSystemAccessRule fsar in fsObj.GetAccessRules(true, true, typeof(System.Security.Principal.NTAccount)))
{
FileSystemRights fsr = fsar.FileSystemRights;
// examine current fsr for permissions...
}
My goal is to determine whether the user has write access to the file.