Company      |       Articles & Research      |      Services      |      Software      |      Contact

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:

C#:
  1. public static void AddRoleAssignment(ISecurableObject securable, SPPrincipal principal, SPRoleDefinition[] roleDefinitions)
  2. {
  3. var roleDefinitionBindings = new SPRoleDefinitionBindingCollection();
  4. foreach (SPRoleDefinition definition in roleDefinitions)
  5. {
  6. roleDefinitionBindings.Add(definition);
  7. }
  8. var roleAssignment = new SPRoleAssignment(principal);
  9. roleAssignment.ImportRoleDefinitionBindings(roleDefinitionBindings);
  10. securable.RoleAssignments.Add(roleAssignment);
  11. }

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.

share save 171 16 Easy Way To Add Role Assignments

Related posts:

  1. Removing Role Definitions from a Role Assignment
  2. SharePoint Security Helper Class
  3. Display A SharePoint Users Role Collection
  4. ADAM (Active Directory In Application Mode) Custom Role Provider
  5. Comparing SPPrincipal Objects To See If Same Member

No Comments »

No comments yet.

RSS feed for comments on this post. TrackBack URL

Leave a comment