4

How do I get the names of all libraries within a given site using jquery/javascript?

the only way i know of is using getByTitle('listtitle'), but I would like all names of libraries (hopefully there is a way to do libraries only and not just all lists) in a site?

Thanks as always!

2 Answers 2

4

I'm not sure if you can query for only libraries tbh, an option is too look at the SP.BaseType. Something like this:

ExecuteOrDelayUntilScriptLoaded(Initialize, "sp.js");
function Initialize()
{
    var clientContext = new SP.ClientContext.get_current();
    var web = clientContext.get_web();
    this.lists = web.get_lists();
    clientContext.load(lists);

    clientContext.executeQueryAsync(Function.createDelegate(this, this.onListItemsLoadSuccess), Function.createDelegate(this, this.onQueryFailed));
}

function onListItemsLoadSuccess(sender, args) {

    var count = this.lists.get_count();

    for (x = 0; x < count; x++)
    {
        if(this.lists.itemAt(x).get_baseType() === 1) {
            var listTitle = this.lists.itemAt(x).get_title();
            console.log(listTitle);
        }
    }              
}

function onQueryFailed(sender, args) {
    alert('request failed ' + args.get_message() + '\n' + args.get_stackTrace());
}
1
  • thanks Anders.....i think baseType === '101' will get me libraries! thanks for the direction. Commented Jun 8, 2013 at 13:24
3

The SiteData web service will return all that data for you. The link is for SP 2007, but it still exists in 2010 and functions the same.

http://<Site>/_vti_bin/SiteData.asmx

I'm not entirely sure where that would fit in within the client object model, but it would be easily accessed with a more familiar tool to me, SPServices.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.