mka*_*car 4 c# sharepoint sharepoint-2007 sharepoint-2010
using (SPSite site = (SPSite)properties.Feature.Parent)
{
using (SPWeb web = site.OpenWeb())
{
if (web != null)
{
web.AllowUnsafeUpdates = true;
SPList list = web.Lists["Alert Status v1.0"];
//Creates a new role assignment for a group
SPGroup myGroup = web.SiteGroups["IKM Manager"];
SPRoleAssignmentCollection roleAssignments = web.RoleAssignments;
// SPRoleAssignment accepts a SPPrincipal which can be a SPUser or SPGroup
SPRoleAssignment roleAssignment = new SPRoleAssignment(myGroup);
//Add the new role assignment to the collection of role assignments for the site.
roleAssignments.Add(roleAssignment);
// Stop inheriting permissions
list.BreakRoleInheritance(true);
list.RoleAssignments.Add(roleAssignment);
list.Update();
Run Code Online (Sandbox Code Playgroud)
我在RoleAssignments.Add(roleAssignment)上有错误,例如"无法添加具有空角色定义绑定集合的角色分配".我想停止继承权限并将特定组添加到列表权限.你能帮助我吗?请..
谢谢
小智 15
这应该工作.
list.BreakRoleInheritance(true);
SPGroup groupAdmin = web.SiteGroups["IKM Manager"];
SPRoleAssignment roleAssignmentAdmin = new SPRoleAssignment((SPPrincipal)groupAdmin);
SPRoleDefinition roleAdmin = web.RoleDefinitions.GetByType(SPRoleType.Administrator);
roleAssignmentAdmin.RoleDefinitionBindings.Add(roleAdmin);
list.RoleAssignments.Add(roleAssignmentAdmin);
list.Update();
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
18456 次 |
最近记录: |