0

我正在尝试运行此处建议的代码: 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);
}
4

1 回答 1

1

您可以尝试使用以下方法从您指定的网络获取所有用户:web.AllUsers

希望能帮到你。

于 2013-07-11T10:39:15.577 回答