I have a group "Visitors" with Contribute permission and I want to change permission to Read, programmatically. I don't have problem with adding new permission to the group, but I don't know how to remove old permission.
How to change this code to remove permission Contribute and add permission 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();
The following example demonstrates how to:
Reader
permission Level to the group Contribute
permission Level from the group Example:
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();
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.