SharePoint Office 365 – How to Get the Lists with Unique Permissions – Programmatically C# CSOM

Sathish Nadarajan
 
Solution Architect
December 6, 2017
 
Rate this article
 
Views
4800

In one of a requirement, need to get the Lists, which has unique permission. The input will be a Site Collection or a collection of site collections, we need to iterate through the webs inside that, and each list and prepare a list of Lists which has unique permission. Hence, thought of coming up with a small method and sharing with the community.

 public static void HasUniquePermission()
         {
             OfficeDevPnP.Core.AuthenticationManager authMgr = new OfficeDevPnP.Core.AuthenticationManager();
 
             string siteUrl = "https://******.sharepoint.com/sites/DeveloperSite/";
             string userName = "Sathish@********.onmicrosoft.com";
             string password = "********";
 
             using (var ctx = authMgr.GetSharePointOnlineAuthenticatedContextTenant(siteUrl, userName, password))
             {
                 Web web = ctx.Web;
                 ctx.Load(web.Lists);
                 ctx.Load(web);
 
                 ctx.ExecuteQueryRetry();
 
                 List list = web.Lists.GetByTitle("D1");
                 ctx.Load(list);
                 ctx.Load(list, li => li.HasUniqueRoleAssignments);
                 ctx.ExecuteQuery();
 
                 System.Console.WriteLine(Convert.ToString(list.HasUniqueRoleAssignments));
             }
         }
 

The Property HasUniqueRoleAssignments gives back TRUE or FALSE.

Happy Coding,

Sathish Nadarajan.

Category : CSOM, Office 365, PNP, SharePoint

Author Info

Sathish Nadarajan
 
Solution Architect
 
Rate this article
 
Sathish is a Microsoft MVP for SharePoint (Office Servers and Services) having 15+ years of experience in Microsoft Technologies. He holds a Masters Degree in Computer Aided Design and Business ...read more
 

Leave a comment