Question

I have been developing an event handler to clean up the RolesAssignments of the new item of a document library in MOSS. I’ve searched for a method that could clean all the RolesAssignments efficiently, although the best way I found seams to be loop through the RolesAssignments and delete one by one? Is there another way to clean all the RolesAssignments for an item?

The code I’m using for cleaning the RolesAssignments look like this:

    for (int i = ListItem.RoleAssignments.Count - 1; i >= 0; --i)
    { 
        ListItem.RoleAssignments.Remove(i); 
    }

Does anyone have any ideas on how to deal with this?

Was it helpful?

Solution 2

I have the answer, put the propertie SPListItem.BreakRoleInheritance(false) to break the role inheritance and remove the role assignments.

OTHER TIPS

The example you've given within the body of your question is the most correct way to do this. ResetRoleInheritance and BreakRoleInheritance may do what you need, but this is the side-effect of the operations they perform. Their purpose is not to remove RoleAssignments, but rather operate on role inheritance. From MSDN:

ResetRoleInheritance - "Removes the local role assignments and reverts to role assignments from the parent object."

BreakRoleInheritance - "Creates unique role assignments for the item rather than inheriting them from a parent."

If role inheritance is already broken and you are using specific role assignments, you should remove them using a loop as you have in your question.

How about ResetRoleInheritance? This should clear out all of the RoleAssignments.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top