3

I am writing a SharePoint CSOM application using the following package:

<package id="Microsoft.SharePointOnline.CSOM" version="16.1.7618.1200" targetFramework="net45" />

In my SharePoint app, I do not care about system sharepoint lists. So I'm finding myself having to devise a way to ignore these lists when getting the lists for a Web.

For now I'm hackily just looking for lists with Hidden or IsCatalog and ignoring them, but this is not a good solution because it causes the query to have to return lists that I don't care about thus slows things down:

ClientContext clientContext = getClientContext(url);
Web web = clientContext.Web;
ListCollection lists = web.Lists;
clientContext.Load(lists);
clientContext.ExecuteQuery();
foreach (List list in lists) {
    if (list.Hidden || list.IsCatalog) {
        continue;
    }
    // Use the list 
}

Is there some sort of flag that I can use when querying for lists to ignore system lists so that I don't fetch unnecessary lists in my client context query?

I would figure you would use a CAML query somehow... like this:

<View><Query><Where><Eq><FieldRef Name=\"Hidden\" /><Value Type=\"Boolean\">0</Value></Eq></Where></Query></View>

But I don't see any CSOM method for Web.GetLists(camlQuery)

I found some posts around here-and-there referencing:

clientContext.Web.Lists.Where

https://msdn.microsoft.com/en-us/library/office/microsoft.sharepoint.client.listcollection_members.aspx

But this doesn't exist in CSOM the Nuget 16.1.x package with target framework of .NET 4.5.

Any ideas?

  • Can you add to your post the code you currently use to retrieve the collection of lists? – sasfrog May 11 '18 at 22:48
  • done. it's very basic stuff. – Nicholas DiPiazza May 12 '18 at 0:02
2

You can pass a filter to the server, so instead of:

clientContext.Load(lists);

Do this:

clientContext.Load(lists, ls=>ls.Where(l => l.Hidden == false && l.IsCatalog == false));

There's a fair bit of efficiency you can gain by passing off to the server your filters and specifying what to include in the response (using include).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.