SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I must solve this problem:

I have a list in which there are stored some SPListItem. On this list a group(AllReplyers) has the "Contribute" privilege, so that everybody can add file. When a user add an element, i want this element to be modifiable only by him, and readable by the others..

I think a good way to do that is to "break" the item privileges, lower to reader the AllReplyer and add the single user to "contribute".. How can i do this programmatically??

Thank you very much!!

share|improve this question
up vote 13 down vote accepted

You can do this like this:

public static void AssignPermissionsToItem(SPListItem item, SPPrincipal obj, SPRoleType roleType)
    if (!item.HasUniqueRoleAssignments)
        item.BreakRoleInheritance(false, true);

    SPRoleAssignment roleAssignment = new SPRoleAssignment(obj);
    SPRoleDefinition roleDefinition = item.Web.RoleDefinitions.GetByType(roleType);


SPPrincipal is a SPUser or SPGroup. About SPRoleType you can read here.

share|improve this answer
To make this method more generic and reusable, pass in a SPSecurableObject instead of SPListItem. This way you can use it to secure SPLists and SPWebs too. Might have to pass in a separate SPWeb to get hold of the SPRoleDefinition though, or you can test the type of the SecurableObject and get it from there after doing a cast to the right type… – Jaap Vossers Feb 2 '12 at 14:20

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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