Create custom permission level using C#,PowerShell and JSOM

Today,I am going to present you to create Permission level using C#, Powershell and JavaScript Object Model. Permission levels are predefined sets of permissions that you can assign to individual users, groups of users, or security groups, based on the functional requirements of the users and on security considerations.

Create Permission Level using C#

 public static void CreatePermissionLevel()
            string strURL = "http://optimumview/";
            string CustomPermissionName = "myCustomPermissions";
            using (SPSite site = new SPSite(strURL))
                using (SPWeb web = site.RootWeb)
                    if (web.RoleDefinitions[CustomPermissionName] == null)
                        SPRoleDefinition role = new SPRoleDefinition();
                        role.Name = CustomPermissionName;
                        role.Description = "Description: It's only permission to ViewListItems,AddListItems and EditListItems";
                        //I'm using below permisson attributes in this code
                        //ViewListItems	View items in lists, documents in document libraries, and view Web discussion comments.
                        //AddListItems	Add items to lists, add documents to document libraries, and add Web discussion comments.
                        //EditListItems	Edit items in lists, edit documents in document libraries, edit Web discussion comments in documents, and customize Web Part Pages in document libraries.
                        role.BasePermissions = SPBasePermissions.ViewListItems | SPBasePermissions.AddListItems | SPBasePermissions.EditListItems;
                        Console.WriteLine("Created Successfully!!");
                        Console.WriteLine("Permisson already exists!!");

Click Here get list of Specifies the built-in permissions available in SharePoint Foundation.

Create Permission Level using Powershell

$spSite = Get-SPSite "http://optimumview/"
$spWeb = $spSite | Get-SPWeb
if($spWeb.RoleDefinitions[$customPermissionName] -eq $null)
    $spRoleDefinition = New-Object Microsoft.SharePoint.SPRoleDefinition
    $spRoleDefinition.Name = $customPermissionName
    $spRoleDefinition.Description = "Description: It's only permission to ViewListItems,AddListItems and EditListItems";
    $spRoleDefinition.BasePermissions = "ViewListItems, AddListItems, EditListItems"
	Write-Host $spRoleDefinition.Name "has been created successfully!!" -foregroundcolor green
	Write-Host "Permission already exists!!" -foregroundcolor red

To get list of Specifies the built-in permissions available in SharePoint Foundation use below PowerShell Command :


Create Permission Level using JavaSript

function createCustomPermisionLevel() {
        var clientContext = new SP.ClientContext.get_current();
        var oWeb = clientContext.get_web();
        var customPermissionName='MyJSOMPermission';
        // Set up permissions.
        var permissions = new SP.BasePermissions();
        // Create a new role definition.
        var roleDefinitionCreationInfo = new SP.RoleDefinitionCreationInformation();
        roleDefinitionCreationInfo.set_description('Its only permission to ViewListItems,AddListItems and EditListItems');
            Function.createDelegate(this, successHandler),
            Function.createDelegate(this, errorHandler)

        function successHandler() {
            alert(customPermissionName +' : has been created sucessfully!');

        function errorHandler() {
            alert("Request failed: " + arguments[1].get_message());

Click Here to get list of permission available in csom.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s