C# Directory SetAccessControl

Description

Directory SetAccessControl Applies access control list (ACL) entries described by a DirectorySecurity object to the specified directory.

Syntax

Directory.SetAccessControl has the following syntax.


public static void SetAccessControl(
  string path,
  DirectorySecurity directorySecurity
)

Parameters

Directory.SetAccessControl has the following parameters.

  • path - A directory to add or remove access control list (ACL) entries from.
  • directorySecurity - A DirectorySecurity object that describes an ACL entry to apply to the directory described by the path parameter.

Returns

Directory.SetAccessControl method returns

Example


using System;//from w  ww .  j a va2 s.  com
using System.IO;
using System.Security.AccessControl;

class DirectoryExample
{
    public static void Main()
    {
        string FileName = "TestDirectory";

        DirectoryInfo dInfo = new DirectoryInfo(FileName);

        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