C# FileInfo SetAccessControl
Description
FileInfo SetAccessControl
Applies access control list
(ACL) entries described by a FileSecurity object to the file described by
the current FileInfo object.
Syntax
FileInfo.SetAccessControl
has the following syntax.
public void SetAccessControl(
FileSecurity fileSecurity
)
Parameters
FileInfo.SetAccessControl
has the following parameters.
fileSecurity
- A FileSecurity object that describes an access control list (ACL) entry to apply to the current file.
Returns
FileInfo.SetAccessControl
method returns
Example
The following code example uses the GetAccessControl method and the SetAccessControl method to add and then remove an ACL entry from a file.
using System;//from w ww . j a va2 s .c o m
using System.IO;
using System.Security.AccessControl;
class FileExample
{
public static void Main()
{
string FileName = "c:/test.xml";
FileInfo fInfo = new FileInfo(FileName);
FileSecurity fSecurity = fInfo.GetAccessControl();
fSecurity.AddAccessRule(new FileSystemAccessRule(@"MyDomain\MyAccessAccount",
FileSystemRights.ReadData,
AccessControlType.Allow));
fInfo.SetAccessControl(fSecurity);
fSecurity.RemoveAccessRule(new FileSystemAccessRule(@"MyDomain\MyAccessAccount",
FileSystemRights.ReadData,
AccessControlType.Allow));
fInfo.SetAccessControl(fSecurity);
}
}