3

I'm new to SharePoint CSOM and I'm trying to get a list of SP Lists/Libraries.

Here's my code:

public LinkedList<string> getLibraries() {
        Web site = spClientContext.Web;
        spClientContext.Load(site.Lists);
        spClientContext.ExecuteQuery();

        LinkedList<string> libraries = new LinkedList<string>();
        foreach (List list in site.Lists)
            libraries.AddLast(list.Title);

        return libraries;
    }

When code is executed CSOM returns all libraries, even those that are hidden from the web interface.
Something like this:

CSOM returned libraries SharePoint 2010 libraries

How can I determine which List/Library to display in my list so that it matches SharePoint UI visible lists?

2

Just check list.Hidden property, then add in libraries

foreach(List list in site.Lists) {
    if (!list.Hidden) {
        libraries.AddLast(list.Title);
    }
}
  • One more question, I have the similar issue with folders, I getting folders which are not visible in the Web UI. Folder's do not have the Hidden property, how do I filter those? – Brlja Feb 22 '16 at 14:46
  • Please ask another question with code – Atish Dipongkor - MVP Feb 22 '16 at 15:35

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.