Reputation: 518
I have the following situation:
AD:
Sharepoint:
The hole point is to add both the users and the groups from AD to Sharepoint. I got adding the users to work using the following code:
User adUser = ctx.Web.EnsureUser(ad.LogOnName);
ctx.Load(adUser);
gc.Users.AddUser(adUser);
ctx.Load(gc, x => x.Users);
Where the LogOnName is the User Principal Name of the user. When adding the groups as LogOnName is used the group name.
Any suggestions where I am mistaken wehn adding the groups?
Upvotes: 0
Views: 491
Reputation: 3655
Below is my sample tested code for your reference:
User group = ctx.Web.EnsureUser("SecurityGroup");
ctx.Load(gc);
User addUser=gc.Users.AddUser(group);
ctx.Load(addUser);
ctx.ExecuteQuery();
Upvotes: 0