public static bool CanIWrite(FileInfo fileInfo) { // this will return true if write or modify or take ownership or any of those other good perms are available. CurrentUserSecurity currentUserSecurity = new CurrentUserSecurity(); FileSystemRights[] fsRights = { FileSystemRights.Write, FileSystemRights.Modify, FileSystemRights.FullControl, FileSystemRights.TakeOwnership, FileSystemRights.ChangePermissions, FileSystemRights.AppendData, FileSystemRights.WriteData }; bool writeRight = false; foreach (FileSystemRights fsRight in fsRights) { try { if (currentUserSecurity.HasAccess(fileInfo, fsRight)) { writeRight = true; } } catch (UnauthorizedAccessException) { return(false); } } return(writeRight); }
public static bool CanIRead(FileInfo fileInfo) { // this will return true if file read perm is available. CurrentUserSecurity currentUserSecurity = new CurrentUserSecurity(); FileSystemRights[] fsRights = { FileSystemRights.Read, FileSystemRights.ReadAndExecute, FileSystemRights.ReadData }; bool readRight = false; foreach (FileSystemRights fsRight in fsRights) { try { if (currentUserSecurity.HasAccess(fileInfo, fsRight)) { readRight = true; } } catch (UnauthorizedAccessException) { return(false); } } return(readRight); }