我正在尝试运行此处建议的代码: https ://sharepoint.stackexchange.com/questions/72431/what-is-the-correct-way-to-add-an-ad-group-to-an-sp-有权限的组
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);
}