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.
Leave a comment