C# - How to use DirectorySecurity.SetOwner() ? I'm having troubles

后端 未结 1 1191
自闭症患者
自闭症患者 2021-01-24 10:37

I\'m having troubles figuring out the SetOwner() method. In my case, I\'ve created an user in Active Directory by code, then, I create a folder for the user.

<
1条回答
  •  别那么骄傲
    2021-01-24 11:11

    Try this

    string pathIntern = @"\\11fil01\brukar\" + user.UserName;               
    DirectoryInfo diIntern       = new DirectoryInfo(pathIntern);
    DirectorySecurity dsecIntern = diIntern.GetAccessControl();
    IdentityReference newUser    = new NTAccount(domain + @”\” + username);
    dsecIntern.SetOwner(newUser);
    FileSystemAccessRule permissions = new FileSystemAccessRule(newUser,FileSystemRights.FullControl, AccessControlType.Allow);
    dsecIntern.AddAccessRule(permissions);
    diIntern.SetAccessControl(dsecIntern);
    

    You can see this link too Create, Read, Update Active Directory Users with C#

    Bye.

    0 讨论(0)
提交回复
热议问题