Monday, July 6, 2009

SPWeb.RoleDefinitions.GetByType(SPRoleType.None)

Hi all

Recently i tried to copy permission from one item to another (see How To Copy Permissions Between Site Collections) , and had a problem with role definition types that were None.
The problem occured when i tried to copy
Restricted Read role agginment.

So to solve it I used this code:

if (roleDefinition.Type != SPRoleType.None)
{
definition = web.RoleDefinitions.GetByType(roleDefinition.Type);
roleAssignment.RoleDefinitionBindings.Add(definition);
}
else
{
definition = web.RoleDefinitions.GetById(roleDefinition.Id);
roleAssignment.RoleDefinitionBindings.Add(definition);
}

Instead of geting the code by role definition type i got it by it's Id.

No comments:

Post a Comment