C# DirectoryInfo GetAccessControl()

Description

DirectoryInfo GetAccessControl() Gets a DirectorySecurity object that encapsulates the access control list (ACL) entries for the directory described by the current DirectoryInfo object.

Syntax

DirectoryInfo.GetAccessControl() has the following syntax.


public DirectorySecurity GetAccessControl()

Returns

DirectoryInfo.GetAccessControl() method returns A DirectorySecurity object that encapsulates the access control rules for the directory.

Example

Gets a DirectorySecurity object that encapsulates the access control list (ACL) entries for the directory described by the current DirectoryInfo object.


using System;//  w  ww.j a va  2  s . c  o m
using System.IO;
using System.Security.AccessControl;

class DirectoryExample
{
    public static void Main()
    {
        string DirectoryName = "TestDirectory";
        DirectoryInfo dInfo = new DirectoryInfo(DirectoryName);
        DirectorySecurity dSecurity = dInfo.GetAccessControl();
        dSecurity.AddAccessRule(new FileSystemAccessRule(@"MYDOMAIN\MyAccount", FileSystemRights.ReadData, AccessControlType.Allow));
        dInfo.SetAccessControl(dSecurity);
        dSecurity.RemoveAccessRule(new FileSystemAccessRule(@"MYDOMAIN\MyAccount", FileSystemRights.ReadData, AccessControlType.Allow));
        dInfo.SetAccessControl(dSecurity);

    }
}




















Home »
  C# Tutorial »
    System.IO »




BinaryReader
BinaryWriter
Directory
DirectoryInfo
DriveInfo
File
FileInfo
FileStream
MemoryStream
Path
StreamReader
StreamWriter
StringReader
StringWriter