0

I need to give permission to some limited users to one of the site page. How can i achieve this programmatically?

For example: If I have created a page programmatically in a library called "SitePages", then that page should be visible to only few people to whom I give permission.

1
  • Please give an example of how you would like this to work. Commented Sep 14, 2015 at 15:20

2 Answers 2

0

This will work I think

                   item.BreakRoleInheritance(false);
                   while (item.RoleAssignments.Count > 0)  
                    { 
                        item.RoleAssignments.Remove(0); 
                    }


                   // Give permissions to a specific group
                   SPUser group = web.EnsureUser(strListItemSecurity_Group);
                   SPRoleAssignment roleassignment_group = new SPRoleAssignment(group);
                   roleassignment_group.RoleDefinitionBindings.Add(web.RoleDefinitions[strTHTListItemSecurity_Group_Role]);
                   item.RoleAssignments.Add(roleassignment_group);
1

There is an code example in this article:

https://msdn.microsoft.com/library/Microsoft.SharePoint.SPRoleAssignment

You would modify it slightly, to add your new role assignment to the page itself, of course.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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