当我删除列表中组的角色分配时,这也会删除子文件夹的角色分配。 (对于子文件夹,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();
有人能指出我正确的方向吗?
答案 0 :(得分:1)
此行为是设计使然。这就像一条链子。如果您拆分继承并为对象(列表)定义新的分配,则所有子对象(子文件夹)现在将继承新的分配,因为它们不再具有与对象(列表)的父对象(网站)的连接。继承被打破了。
如果您希望子文件夹具有与列表的父对象(网站)相同的分配。请尝试以下方法:
但随着连锁店的分手。您在网站上所做的任何更改都不会影响子文件夹。如果网站和子文件夹仍应保持同步(关于作业),您必须自己确定一些方法。