以编程方式将用户权限添加到Sharepoint中的列表

时间:2008-12-11 07:51:49

标签: c# sharepoint permissions moss

如何以编程方式将用户权限添加到Sharepoint中的列表?我想将权限“Contribute”添加到某个列表的用户或组。我正在使用C#。

1 个答案:

答案 0 :(得分:11)

您可以使用SPRoleAssignment对象执行此操作,例如

// Assuming you already have SPWeb and SPList objects
...
SPRoleAssignment roleAssignment = new SPRoleAssignment("dom\\user", "user@dom", "user", "some notes");
SPRoleDefinition roleDefinition = web.RoleDefinitions.GetByType(SPRoleType.Contributor);
roleAssignment.RoleDefinitionBindings.Add(roleDefinition);
if (!myList.HasUniqueRoleAssignments)
{
    myList.BreakRoleInheritance(true); // Ensure we don't inherit permissions from parent
} 
myList.RoleAssignments.Add(roleAssignment);
myList.Update();