Easy Way To Add Role Assignments

I have to do this all the time. If you have a similar requirement, just use the following method:


public static void AddRoleAssignment(ISecurableObject securable, SPPrincipal principal, SPRoleDefinition[] roleDefinitions)
var roleDefinitionBindings = new SPRoleDefinitionBindingCollection();
foreach (SPRoleDefinition definition in roleDefinitions)
var roleAssignment = new SPRoleAssignment(principal);


The usage of it is pretty straightforward, you have an ISecurableObject parameter to expose role assignments for an object, an SPPrincipal to represent a user or group, and a SPRoleDefinition array to act as a container for role definitions.