Untitled
unknown
plain_text
a year ago
1.5 kB
7
Indexable
public static void RemoveFileSecurity(string FileName, string Account, FileSystemRights Rights, AccessControlType ControlType) { FileName = "D:\\uploads\\filename.pdf"; // Create a new FileInfo object. FileInfo fInfo = new FileInfo(FileName); // Get a FileSecurity object that represents the // current security settings. FileSecurity fSecurity = fInfo.GetAccessControl(); // identify and remove execute access rules AuthorizationRuleCollection accessRules = fSecurity.GetAccessRules(true, true, typeof(NTAccount)); foreach (FileSystemAccessRule rule in accessRules) { if ((rule.FileSystemRights & FileSystemRights.ExecuteFile) == FileSystemRights.ExecuteFile) { // Remove the execute access rule fSecurity.RemoveAccessRule(rule); } } // Add the FileSystemAccessRule to the security settings. //fSecurity.RemoveAccessRule(new FileSystemAccessRule(Account, // Rights, // ControlType)); // Set the new access settings. fInfo.SetAccessControl(fSecurity); // fInfo.SetAccessControl(FileName, fSecurity); }
Editor is loading...
Leave a Comment