How to Break the Role Inheritance (Stop Inheriting Permissions) and assign with Unique Permissions for SharePoint list and Folders Programmatically C# CSOM

Sathish Nadarajan
Solution Architect
December 6, 2017
Rate this article
[Total: 0    Average: 0/5]

In this article, let us see, how to Break the Role Inheritance and Assign Permissions to the SharePoint Lists Programmatically using C# CSOM.

By Default, when I create a List, the permission will be inherited from the Parent Web.


We need to “Stop Inheriting Permissions” and give permissions only the required group or users.

Let us see, how to do that, programmatically.

 public static void BreakPermissions()
             OfficeDevPnP.Core.AuthenticationManager authMgr = new OfficeDevPnP.Core.AuthenticationManager();
             string siteUrl = "https://******";
             string userName = "Sathish@********";
             string password = "**********";
             using (var ctx = authMgr.GetSharePointOnlineAuthenticatedContextTenant(siteUrl, userName, password))
                 Web web = ctx.Web;
                 List list = web.Lists.GetByTitle("MyList");
                 list.BreakRoleInheritance(false, true);
                 list.AddPermissionLevelToUser("User1@****", "Read", false);

After the Code Execution, the permission screen looks like below.


The Same applies to the Folder as well.

 Folder projectFolder =
                             web.GetFolderByServerRelativeUrl(                                "/sites/MySite/MyList/MyFolder”);
                             projectFolder.ListItemAllFields.BreakRoleInheritance(false, true);
 projectFolder. ListItemAllFields.AddPermissionLevelToUser("User1@****", "Read", false);

In the same manner, we can add Permission Level the Groups as well.

 projectFolder.ListItemAllFields.AddPermissionLevelToGroup("MyGroup", "Read", false);

Note: There is no method available to break the permission and assign for Item Level in PNP. (At least by the time of writing this article). Probably, if it is released in the upcoming versions, we can update this section.

Happy Coding,

Sathish Nadarajan.

Author Info

Sathish Nadarajan
Solution Architect
Rate this article
[Total: 0    Average: 0/5]
Sathish is a Microsoft MVP for SharePoint (Office Servers and Services) having 13+ years of experience in Microsoft Technologies. He holds a Masters Degree in Computer Aided Design and Business more

Leave a comment