Search code examples
c#sharepointsharepoint-2010

How to get restricted properties from Web for whole collection in SharePoint


I want to have few Web properties avalieble in my code which are not by default. For example, if I load Website with clientContext.Load(clientContext.Web.Webs) I don't get the "HasUniqueRoleAssignments" property. According to MSDN I can easily get them with lambda expresion. It works fine for geting properties I want from a single website

clientContext.Load(clientContext.Web,  website => website.Title,   website => website.HasUniqueRoleAssignments,  website => website.RoleAssignments);

but I want to get whole collection of websites at once. I was trying to do sth like this

clientContext.Load(clientContext.Web.Webs,  website => website.Title,   website => website.HasUniqueRoleAssignments,  website => website.RoleAssignments);

but it didn't run.

Anyone knows how to solve this out? Thanks in advance.


Solution

  • The following example demonstrates how to retrieve HasUniqueRoleAssignments property for web site collection:

    using (var ctx = new ClientContext(webUri))
    {            
    
        ctx.Load(ctx.Web.Webs, wcol => wcol.Include(w => w.HasUniqueRoleAssignments, w => w.Title, w => w.RoleAssignments));
        ctx.ExecuteQuery();
    
        foreach (var web in ctx.Web.Webs)
        {
            Console.WriteLine(web.HasUniqueRoleAssignments);
        }
    }