Monday, August 5, 2013

C# code to reset permissions of webpart page in sharepoint

Here is the small peace of code to reset the permissions of a sharepoint page.

Following are the steps i am doing here.

1. Breaking the role inheritance
2. Remove all the permissions of the file
3. Giving access to only the site owners group

public void ResetASPXPagePermissions(SPFile file, SPWeb web)


            SPRoleAssignmentCollection SPRoleAssColn = file.Item.RoleAssignments;
            for (int i = SPRoleAssColn.Count - 1; i >= 0; i--)
            SPGroup grp = web.AssociatedOwnerGroup;
            if (grp != null)
                SPRoleAssignment Assignment = web.RoleAssignments.GetAssignmentByPrincipal((SPPrincipal)grp);

Thank you !!

No comments:

Post a Comment