Programmatically give permission to SharePoint site pages
-
05-10-2020 - |
Вопрос
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.
Не связан с sharepoint.stackexchange