将SPRoleAssignment更改为SPList而不影响子文件夹

时间:2011-04-05 09:27:47

标签: sharepoint splist spgroup

当我删除列表中组的角色分配时,这也会删除子文件夹的角色分配。 (对于子文件夹,BreakInheritance == True。)

我的代码:

//BreakRoleInheritance on list
list.BreakRoleInheritance(true);

//Initiate a roledefinition for read only
SPRoleDefinition readerRoleDef = web.RoleDefinitions.GetByType(SPRoleType.Reader);

//Creates a roleassignment bound to the group
SPRoleAssignment readerRole = new SPRoleAssignment(group);

//Add the definition to the roleassignment
readerRole.RoleDefinitionBindings.Add(readerRoleDef);

//Gets the roledefinitions for the given group
var roleAssignements = list.RoleAssignments.Cast<SPRoleAssignment>().Where(r => r.Member.ID == group.ID);

//I would like to to something like this, but this code here affects roleassignments on subfolders as well: 
roleAssignements.ToList().ForEach(r => list.RoleAssignments.RemoveById(r.Member.ID)); 

//Add the new, read role assignment
list.RoleAssignments.Add(readerRole);

//Save changes to the list
list.Update();

有人能指出我正确的方向吗?

1 个答案:

答案 0 :(得分:1)

此行为是设计使然。这就像一条链子。如果您拆分继承并为对象(列表)定义新的分配,则所有子对象(子文件夹)现在将继承新的分配,因为它们不再具有与对象(列表)的父对象(网站)的连接。继承被打破了。

如果您希望子文件夹具有与列表的父对象(网站)相同的分配。请尝试以下方法:

  1. 像在代码中一样分解列表中的继承。
  2. 然后在调用BreakRoleInheritance()时将参数设置为true分解每个子文件夹的继承。目前,所有对象仍应具有相同的赋值,但不从父对象继承它们。
  3. 如果您现在编辑列表的分配,子文件夹仍将具有列表的父对象(网站)的分配。
  4. 但随着连锁店的分手。您在网站上所做的任何更改都不会影响子文件夹。如果网站和子文件夹仍应保持同步(关于作业),您必须自己确定一些方法。

相关问题