0

My scenario is I am having two lists X and Y . Of which both have broken inheritance and having unique permissions. Now i am trying to add new group to the list permissions and assign read only access to that group. How to follow to do so programatically. I am using SharePoint 2010. Till now i was succesfull to create groups to the list permissions. but unable to make group as read only to the list.Thanks in advance.

0

You should add new role definition to the list’s role assignments collection.

Here is the code to do that:

SPList list = …//your list
SPPrincipal principal = …//user or group;

SPRoleAssignment roleAssignment = new SPRoleAssignment(principal);
SPRoleDefinition roleDefinition = new SPRoleDefinition();
roleDefinition = list.ParentWeb.RoleDefinitions.GetByType(SPRoleType.Reader);
SPRoleDefinitionBindingCollection roleDefinitionBindingCollection = new SPRoleDefinitionBindingCollection();
roleDefinitionBindingCollection.Add(roleDefinition);
roleAssignment.ImportRoleDefinitionBindings(roleDefinitionBindingCollection);
list.ParentWeb.AllowUnsafeUpdates = true;
list.RoleAssignments.Add(roleAssignment);
list.ParentWeb.AllowUnsafeUpdates = false;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.