26. April 2013 08:45
/
Vitaly Zayko
/
/
Comments (0)
Let's say you need to create a folder on behalf of a user and protect it from access by anyone but this user. Use DirectorySecurity.SetAccessRuleProtection procedure like this:
DirectoryInfo dir = new DirectoryInfo (DirPath);
if (!dir.Exists)
{
dir.Create();
DirectorySecurity ds = dir.GetAccessControl();
ds.SetAccessRuleProtection(true , false );
ds.AddAccessRule(new FileSystemAccessRule (DomainName + "\\\\" + UserName,
FileSystemRights .FullControl, AccessControlType .Allow));
dir.SetAccessControl(ds);
}
Please be noted that local administrator could request and get access rights even for protected folders. Admins are admins.
4059305d-8abe-416c-96b8-ac6940a9cccc|0|.0|96d5b379-7e1d-4dac-a6ba-1e50db561b04