开发者

Changing SPRoleAssignment to SPList without affecting subfolders

When I remove the roleassignments for the group on the list, this also removes the roleassignments for the subfolders. (BreakInheritance == True for the subfolders. )

My code:

//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 li开发者_开发技巧ke 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();

Can someone point me in the right direction?


This behavior is by design. It's like a chain. If you break up the inheritance and define new assignments for an object (list), all sub objects (sub folders) will now inherit the new assignments because they no more have connection to the parent object (website) of the object (list) on which the inheritance was broken.

If you want the sub folders to have the same assignments as the list's parent object (website). Try the following:

  1. Break up the inheritance on the list as you did in you code.
  2. Then break up the inheritance for each sub folder also with the parameter set to true when calling BreakRoleInheritance(). At the moment all objects should still have the same assignments but without inheriting them form the parent object.
  3. If you now edit the assignments for the list the sub folders will still have the assignments of the list's parent object (website).

But as the chain was broke up. Any changes you make on the website won't affect the sub folders. If the website and the sub folders should still be in sync (regarding the assignments) you have to assure this by yourself some how.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜