我有一个具有Contribute权限的“访问者”组,我想以编程方式更改Read的权限。我没有向组添加新权限的问题,但我不知道如何删除旧权限。
如何更改此代码以删除权限Contribute并添加权限Read?
SPWeb root = site.RootWeb;
SPGroup group = root.SiteGroups["Visitors"];
SPRoleDefinition roleDefinition = root.RoleDefinitions.GetByType(SPRoleType.Reader);
SPRoleAssignment roleAssignment = new SPRoleAssignment(group);
roleAssignment.RoleDefinitionBindings.Add(roleDefinition);
root.RoleAssignments.Add(roleAssignment);
root.Update();
答案 0 :(得分:2)
以下示例演示如何:
Reader
权限级别Contribute
权限级别示例:
SPWeb root = site.RootWeb;
SPGroup group = root.SiteGroups[groupName];
SPRoleDefinition contributeRoleDef = root.RoleDefinitions.GetByType(SPRoleType.Contributor);
SPRoleDefinition readerRoleDef = root.RoleDefinitions.GetByType(SPRoleType.Reader);
SPRoleAssignment groupRoleAssignments = root.RoleAssignments.GetAssignmentByPrincipal(group);
groupRoleAssignments.RoleDefinitionBindings.Remove(contributeRoleDef);
groupRoleAssignments.RoleDefinitionBindings.Add(readerRoleDef);
groupRoleAssignments.Update();