Using the SharePoint 2010 Managed Client Object Model – Filtering the Child Collection returned by LoadQuery using LINQ

This is a clipboard friendly version of example #10, Filtering the Child Collection returned by LoadQuery using LINQ, from Using the SharePoint 2010 Managed Client Object Model.

This blog is inactive.
New blog: EricWhite.com/blog

Blog TOC

using System;
using System.Linq;
using System.Collections.Generic;
using Microsoft.SharePoint.Client;

class Program
{
static void Main(string[] args)
{
ClientContext clientContext =
new ClientContext("https://intranet.contoso.com");
ListCollection listCollection = clientContext.Web.Lists;
IEnumerable<List> hiddenLists = clientContext.LoadQuery(
listCollection
.Where(list => !list.Hidden &&
list.BaseType == BaseType.DocumentLibrary));
clientContext.ExecuteQuery();
foreach (var list in hiddenLists)
Console.WriteLine(list.Title);
}
}

Following is the same example using fully qualified names for better discoverability.

using System;
using System.Linq;
using System.Collections.Generic;

class Program
{
static void Main(string[] args)
{
Microsoft.SharePoint.Client.ClientContext clientContext =
new Microsoft.SharePoint.Client.ClientContext("https://intranet.contoso.com");
Microsoft.SharePoint.Client.ListCollection listCollection = clientContext.Web.Lists;
IEnumerable<Microsoft.SharePoint.Client.List> hiddenLists = clientContext.LoadQuery(
listCollection
.Where(list => !list.Hidden &&
list.BaseType == Microsoft.SharePoint.Client.BaseType.DocumentLibrary));
clientContext.ExecuteQuery();
foreach (var list in hiddenLists)
Console.WriteLine(list.Title);
}
}