我正在尝试运行此处建议的代码: https://sharepoint.stackexchange.com/questions/72431/what-is-the-correct-way-to-add-an-ad-group-to-an-sp-group-with-permissions
EnsureUser行正常工作,但在web.Users行上,它表示用户未找到。
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);
}
答案 0 :(得分:1)
您可以尝试使用以下方法从您指定的网站获取所有用户: web.AllUsers
希望能帮到你。