Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

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!

share|improve this question

2 Answers 2

up vote 2 down vote accepted

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());
}
share|improve this answer
    
thanks Anders.....i think baseType === '101' will get me libraries! thanks for the direction. –  Justin Jun 8 '13 at 13:24

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.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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