Dismiss Notice

Register now to be one of the first members of this SharePoint Community! Click here it just takes seconds!

Dismiss Notice
Welcome Guest from Country Flag

How to Create Custom Permission Level in SharePoint Office 365 Programmatically using C#...

Discussion in 'SharePoint Blogs' started by sathishnadarajan,, Apr 7, 2017.

Thread Status:
Not open for further replies.
  1. sathishnadarajan,

    sathishnadarajan, Guest

    Blog Posts:
    Sometime, the default Permission Levels will not be sufficient for our application and the requirement. Here, let us see how to create a Permission Level through code. Before that, let us have a look, how to create the same on the Screen.
    1. Go to the Site Settings.
    2. Click on Site Permissions.

    3. Click on Permission Levels on the Ribbon.

    4. Click on Add a Permission Level and fill up the details on the screen shown below.

    5. I have selected all the Permissions in this example. This is something similar to Full Control Permission Level.
    6. Click on Create Button.

    7. Now, your permission level is available to assign with any User / group.
    Now, let us see, how to create the same Permission Level Programmatically.

    namespace Console.Office365
    using Microsoft.SharePoint.Client;
    using Microsoft.SharePoint.Client.Taxonomy;
    using Newtonsoft.Json.Linq;
    using OfficeDevPnP.Core.Entities;
    using System;
    using System.Collections.Generic;
    using System.IO;
    using System.Linq;
    using System.Reflection;
    using System.Threading.Tasks;

    class Program
    static void Main(string[] args)


    public static void CreateCustomPermissionLevel()
    OfficeDevPnP.Core.AuthenticationManager authMgr = new OfficeDevPnP.Core.AuthenticationManager();

    string siteUrl = "https://*****.sharepoint.com/sites/communitysite";
    string userName = "[email protected]*******.onmicrosoft.com";
    string password = "****************";

    using (var clientContext = authMgr.GetSharePointOnlineAuthenticatedContextTenant(siteUrl, userName, password))
    Web web = clientContext.Web;
    var roleDefinitions = web.RoleDefinitions;

    // Get Full Control Role Definition
    var fullControlRoleDefinition = roleDefinitions.GetByName("Full Control");

    // Create New Custom Permission Level
    RoleDefinitionCreationInformation roleDefinitionCreationInformation = new RoleDefinitionCreationInformation();
    roleDefinitionCreationInformation.BasePermissions = fullControlRoleDefinition.BasePermissions;
    roleDefinitionCreationInformation.Name = "MyPermissionLevelCreatedByCode";
    roleDefinitionCreationInformation.Description = "Custom Permission Level, Inherited from the Full Control";





    8. This code will create the custom permission level as shown below.

    Happy Coding,
    Sathish Nadarajan.

    Continue reading...
Thread Status:
Not open for further replies.

Share This Page

LiveZilla Live Chat Software