Reputation: 33998
I am trying to run the code suggested here: https://sharepoint.stackexchange.com/questions/72431/what-is-the-correct-way-to-add-an-ad-group-to-an-sp-group-with-permissions
The EnsureUser line works, but on the web.Users line, it says user not found.
var membersGroup = web.SiteGroups.GetByName(string.Concat(web.Title, " ", "Members"));
if (!string.IsNullOrEmpty(xlosgroupname))
{
string xlosgroupnamewithdomain = string.Concat(domainName, @"\", xlosgroupname);
web.EnsureUser(xlosgroupnamewithdomain);
var adLosGroup = web.Users[xlosgroupnamewithdomain];
membersGroup.Users.Add(adLosGroup.LoginName, string.Empty, adLosGroup.Name, adLosGroup.Notes);
SPRoleDefinition contribute = web.RoleDefinitions.GetByType(SPRoleType.Contributor);
SPRoleAssignmentCollection roleAssignments = web.RoleAssignments;
SPRoleAssignment roleAssignment = new SPRoleAssignment(xlosgroupnamewithdomain, string.Empty, string.Empty, string.Empty);
SPRoleDefinitionBindingCollection roleDefBindings = roleAssignment.RoleDefinitionBindings;
roleDefBindings.Add(contribute);
roleAssignments.Add(roleAssignment);
}
Upvotes: 0
Views: 399
Reputation: 490
You can try to get all users from the web you specified using the following method: web.AllUsers
Wish that can help you.
Upvotes: 1