hi team,
I need to break item level permissions on a document library for the current user + the admin group.
i.e. the users will be able to see and edit only their docs; the admins will have full control.
For this I am using the below code:
item.File.CheckOut(); item.BreakRoleInheritance(false); SPRoleDefinitionCollection webroledefinitions = oWeb.RoleDefinitions; SPRoleAssignment roleassignment = new SPRoleAssignment(currentUser); roleassignment.RoleDefinitionBindings.Add(webroledefinitions["Contribute"]); item.RoleAssignments.Add(roleassignment);
Now, after doing this for all the existing files in the library, I found that the admin group users are not able to see ALL files in library.
Please suggest if I need to repeat the above code for the group as well ?
I tried that as well by changing SPRoleAssignment (may be wrong):
SPRoleAssignment roleassignment2 = new SPRoleAssignment((SPPrincipal)admingrp); roleassignment.RoleDefinitionBindings.Add(webroledefinitions["Full Control"]); item.RoleAssignments.Add(roleassignment2);
but I get exception on adding: Cannot add a role assignment with empty role definition binding collection.
Please suggest. Thanks.
Regards, Nayan