views:

313

answers:

3

Hello guys...

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); 
    }

Can you please, point me to the right place to ask about this? Or any ideas how to deal with this..

Best regards

A: 

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

jwmiller5
That Doesn't clear the roles just re associates to whatever roles are in the Site or Subsite level.
Gabriel Guimarães
+1  A: 

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

Esteban Lalinde
+2  A: 

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.

Alex Angas
Thats correct, and if he's changing the roles, it means it's already broken, so he need's to clear them in any way.I do it like this:SPRoleAssignmentCollection roles = item.RoleAssignments;while (roles.Count > 0) roles.Remove(0);
Gabriel Guimarães