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


Sathish Nadarajan
SharePoint MVP
Published On :   06 Dec 2017
Visit Count
Today :  8    Total :   285
Plan, Migrate, Secure, Report
SharePoint & Office 365 Tool. Simple & Easy to Use. 15-Day Trial!

SharePoint Office 365 Tool
Simple & Powerful Tool for Migration, Security & Reporting. Free Trial


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.

SharePoint Usage Reports
Usage reports, collaboration and audit for SharePoint.
Categories

KWizCom Scan