C# FileInfo GetAccessControl()
Description
FileInfo GetAccessControl()
Gets a FileSecurity object
that encapsulates the access control list (ACL) entries for the file described
by the current FileInfo object.
Syntax
FileInfo.GetAccessControl()
has the following syntax.
public FileSecurity GetAccessControl()
Returns
FileInfo.GetAccessControl()
method returns A FileSecurity object that encapsulates the access control rules for the
current file.
Example
The following code example uses the GetAccessControl method and the SetAccessControl method.
// w ww . j av a 2 s . co m
using System;
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);
}
}