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

I try to dynamically get the names of all the lists in my site using a content query web part, but apparently a CQWB can only retrieve the items in the list, but not the list name? I'm wondering how can i go this, maybe using jquery? Thank you very much for your help!!!

share|improve this question
add comment

3 Answers 3

GetListCollection in Lists.asmx will get this for you.

http://msdn.microsoft.com/en-us/library/websvclists.lists.getlistcollection.aspx

Not yet sure if SPServices has implemented this, if not - give @sympmarc a shout on Twitter and suggest it to him :)

share|improve this answer
    
SPServices currently does not have a wrapper for GetListCollection according to the documentation. –  PirateEric Aug 1 '12 at 18:21
    
Just checked - spservices.codeplex.com/… - apparently it does? I'll let Marc add more info. –  James Love Aug 1 '12 at 18:22
    
herpaderp, there just aren't any example pages of it being used. –  PirateEric Aug 1 '12 at 18:24
    
GetListCollection has been there since way back in v0.2.3. Forever! –  Marc D Anderson Aug 1 '12 at 19:17
add comment

+1 @james

Here's the documentation to the SPServices library. http://spservices.codeplex.com/wikipage?title=Lists&referringTitle=%24%28%29.SPServices

There isn't an example on there, but I'll post one here:

    $().SPServices({ 
        operation: "GetListCollection", 
        completefunc: function( xData, Status ) {
            console.log( Status );
            console.log( xData.responseText );

            $( xData.responseXML ).find("Lists > List").each(function() {
                var $node = $(this);

                console.log( $node.attr("Title") );
            });
        } 
});

Hope this helps!

share|improve this answer
    
I was wondering if it can list out all the items inside the List and their types. (refer to qns - sharepoint.stackexchange.com/questions/44282/… –  Jack Aug 27 '12 at 5:14
add comment

Another option is to use the JavaScript Client Object Model:

ExecuteOrDelayUntilScriptLoaded(function(){

    var clientContext = new SP.ClientContext.get_current();
    var web = clientContext.get_web();
    var lists = web.get_lists();
    clientContext.load(lists);
    clientContext.executeQueryAsync(Function.createDelegate(this, this.onListsQuerySucceeded), Function.createDelegate(this, this.onListsQueryFailed));

    function onListsQuerySucceeded() {
        var listEnumerator = lists.getEnumerator();
        while (listEnumerator.moveNext()) {
            var oList = listEnumerator.get_current();
            //Do something with oList.
        }
    }  

    function onListsQueryFailed(sender,args) {
        alert("Failed: "+ args.get_message());      }
},"sp.js");
share|improve this answer
add comment

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.