I have certain page in SharePoint where i need to break inheritance remove certain security groups form the permissions permanently.Al i want to do is through programatically to be done.Please suggest any ideas on this. Thanks.


You can follow this post:
Assigning SharePoint List Item level permission programmatically

Excerpt from article:

RemoveAllPermissions Function

private static void RemoveAllPermissions(SPListItem CurrentlistItem)
        //The below function Breaks the role assignment inheritance for the list and gives the current list its own copy of the role assignments
        //Get the list of Role Assignments to list item and remove one by one.
        SPRoleAssignmentCollection SPRoleAssColn = CurrentlistItem.RoleAssignments;
        for (int i = SPRoleAssColn.Count - 1; i >= 0; i--)

GrantPermission Function

private static void GrantPermission(SPListItem CurrentListItem, SPWeb oSPWeb, SPRoleType SPRoleType, SPPrincipal SPPrincipal)
            //Create one Role Definition i.e Full Controls, Contribute rights or Read rights etc.
            SPRoleDefinition oSPRoleDefinition = oSPWeb.RoleDefinitions.GetByType(SPRoleType);
            //Create one Role Assignment for the specified SP user or group.
            SPRoleAssignment oSPRoleAssignment = new SPRoleAssignment(SPPrincipal);
            //Bind the role definition to the role assignment object created for the user or group.
            //Add it to the specified list item.
            //update the list item so that specified user assignment will have the access.
        catch (Exception ex)
            EventLog.WriteEntry("Error in UAR Initiation Workflow", "GrantPermission() : " + ex.Message);

You can get the List Item for SPFile using SPFile.Item

  • HI Adam i want to break permissions for page not list.Can you please suggest. – SPLearner Sep 26 '13 at 17:23
  • Yes Page is actually an item of Document Library.. you can get the page list item by SPFile.Item property ! – Arsalan Adam Khatri Sep 27 '13 at 16:27

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.