2008-12-11 87 views

回答

11

您可以使用SPRoleAssignment對象(例如,

// Assuming you already have SPWeb and SPList objects 
... 
SPRoleAssignment roleAssignment = new SPRoleAssignment("dom\\user", "[email protected]", "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(); 
+0

我認爲您的評論「確保我們不從父母繼承權限」與代碼不一致,它應該是myList,BreakRoleInheritance(false)。 – csgero 2008-12-11 08:44:43

相關問題