Ramon Torras

TECHNOLOGY ENTHUSIAST

Basic permission operations with CSOM (Client-side Object Model)

The CSOM actually provides great support for working with the security model in SharePoint.

You can do everything from getting a list of groups and members to enumerating roles (permissions levels), the rights associated with them, creating new users and groups, breaking inheritance, and more.

I will try to gather all the useful snippets:

  • Read the associated groups to the web
  • Get userprincipal or groupprincipal
  • Get role by roletype
  • Add a new role to the web
  • Add a new custom role to the list

Read the associated groups to the web

  • AssociatedMemberGroup
  • AssociatedMemberGroup
  • AssociatedVisitorGroup

àSample

Get userprincipal or groupprincipal

this works with users and groups by name

 

Get role by roletype

Possible roletypes

  • SP.RoleType.Guest
  • SP.RoleType.Reader
  • SP.RoleType.Contributor
  • SP.RoleType.WebDesigner
  • SP.RoleType.Administrator
  • SP.RoleType.Editor

Add a new role to the web

 

Add a new custom role to the list