Вопрос

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.

Это было полезно?

Решение

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);

Другие советы

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.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с sharepoint.stackexchange
scroll top