

' Add the access control entry to the file.ĪddFileSecurity(fileName, "DomainName\AccountName", _įileSystemRights.ReadData, AccessControlType.Allow)Ĭonsole.WriteLine("Removing access control entry from " & fileName) Remove the FileSystemAccessRule from the security settings.įSecurity.RemoveAccessRule(new FileSystemAccessRule(account,Ĭonsole.WriteLine("Adding access control entry for " & fileName) Public static void RemoveFileSecurity(string fileName, string account, Removes an ACL entry on the specified file for the specified account. Add the FileSystemAccessRule to the security settings.įSecurity.AddAccessRule(new FileSystemAccessRule(account,įile.SetAccessControl(fileName, fSecurity) Get a FileSecurity object that represents theįileSecurity fSecurity = File.GetAccessControl(fileName)

Public static void AddFileSecurity(string fileName, string account,įileSystemRights rights, AccessControlType controlType) Adds an ACL entry on the specified file for the specified account. RemoveFileSecurity(fileName, AccessControlType.Allow) Remove the access control entry from the file.

Add the access control entry to the file.ĪddFileSecurity(fileName, AccessControlType.Allow) Ĭonsole.WriteLine("Removing access control entry from "

using System Ĭonsole.WriteLine("Adding access control entry for " Use the same procedure for the FileInfo, Directory, and DirectoryInfo classes. You must use a valid user or group account to run this example. To apply the changes, pass the DirectorySecurity object to the Directory.SetAccessControl method. To apply the changes, pass the FileSecurity object to the File.SetAccessControl method.Īdd or remove an ACL entry from a directoryĬall the Directory.GetAccessControl method to get a DirectorySecurity object that contains the current ACL entries of a directory.Īdd or remove ACL entries from the DirectorySecurity object returned from step 1. Add or remove an ACL entry from a fileĬall the File.GetAccessControl method to get a FileSecurity object that contains the current ACL entries of a file.Īdd or remove ACL entries from the FileSecurity object returned from step 1. Modify the object, and then apply it back to the file or directory. To add or remove Access Control List (ACL) entries to or from a file or directory, get the FileSecurity or DirectorySecurity object from the file or directory.
