0

There is requirement to create a list by using some already available list template with unique permission. But when i am creating any list, by default all the user permissions are getting inherited then i have to click "stop inheritance" option and then remove all the users from permission list.

Can we create a list with unique permission such that there is no user in permission list?

Thanks.

  • You can stop inheritance programmatically and then remove the permissions & assign permissions which you need. If you need code for this then I can provide you. – Ronak Patel Feb 16 '15 at 10:09
  • It means it is not possible with OOB feature.Please provide me the code. – ARD Feb 16 '15 at 13:02
1

Stop inheritance & remove all permissions on the list and assign the permission to User on List :

SPList list = web.Lists["myList"];

list.BreakRoleInheritance(false,false); // break inheritance & remove parent permissions

// Now assign permission to "user1"
SPUser spUser = web.EnsureUser("user1");  
SPRoleAssignment roleAssignment = new SPRoleAssignment(spUser);  
SPRoleDefinition roleDefinition = new SPRoleDefinition();

roleDefinition = web.RoleDefinitions.GetByType(SPRoleType.Reader); // Give Permission to User on this List

SPRoleDefinitionBindingCollection roleDefinitionBindingCollection = new SPRoleDefinitionBindingCollection();
roleDefinitionBindingCollection.Add(roleDefinition);
roleAssignment.ImportRoleDefinitionBindings(roleDefinitionBindingCollection);
list.RoleAssignments.Add(roleAssignment);
list.Update();

Now, only 'user1' have permission on the list.

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.