Quantcast
Channel: SharePoint 2013 - Development and Programming forum
Viewing all articles
Browse latest Browse all 7589

Breaking item level permissions

$
0
0

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


Viewing all articles
Browse latest Browse all 7589

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>