Вот пример кода:
public bool SetAcl(string pathname, string userRights, string username, bool inheritSubDirectories)
{
if (string.IsNullOrEmpty(pathname))
{
return false;
}
pathname = pathname.TrimEnd('\\');
var rights = (FileSystemRights)0;
if (userRights == "R")
{
rights = FileSystemRights.ReadAndExecute;
}
else if (userRights == "C")
{
rights = FileSystemRights.ChangePermissions;
}
else if (userRights == "F")
{
rights = FileSystemRights.FullControl;
}
var accessRule = new FileSystemAccessRule(username, rights,
InheritanceFlags.None,
PropagationFlags.NoPropagateInherit,
AccessControlType.Allow);
var info = new DirectoryInfo(pathname);
var security = info.GetAccessControl(AccessControlSections.Access);
bool result;
security.ModifyAccessRule(AccessControlModification.Set, accessRule, out result);
if (!result)
{
return false;
}
InheritanceFlags iFlags = InheritanceFlags.ObjectInherit;
if (inheritSubDirectories)
{
iFlags = InheritanceFlags.ContainerInherit | InheritanceFlags.ObjectInherit;
}
accessRule = new FileSystemAccessRule(username, rights,
iFlags,
PropagationFlags.InheritOnly,
AccessControlType.Allow);
security.ModifyAccessRule(AccessControlModification.Add, accessRule, out result);
if (!result)
{
return false;
}
info.SetAccessControl(security);
return true;
}
Код основан на материале поста Setting ACE/ACL permissions in .NET 2.0