3

I need to setup a list to display all the document libraries in a given subsite. This list will be part of this subsite as well.

I've seen several references here in the forum where ppl use C# code to query the lists and document libraries, filter the results to get only the document libraries and then display those items. But I'm using Sharepoint Online and I don't see the way to add C# code to it, not even through SP Designer 2013.

Thanks in advance !

5
  • You can easily achieve this using JavaScript and REST API. Commented Jan 13, 2015 at 22:42
  • Do do you have more info about this? Maybe a sample code snippet? Thanks !
    – gsandorx
    Commented Jan 13, 2015 at 22:59
  • gsandorx: Check my answer. Commented Jan 13, 2015 at 23:01
  • Are you driving any actions from the list, such as workflow, or some other management function? Of do you just need the list for a report type of function? Commented Jan 14, 2015 at 2:15
  • I actually need to present a list where one of the columns contain the listing of my current document libraries. Each library would be listed in a separate row. That's it :)
    – gsandorx
    Commented Jan 15, 2015 at 18:11

2 Answers 2

1

Just in case anyone comes across this and can't get it to work:

Add a $ before the filter in the URL - i.e. /_api/web/lists?$filter=BaseTemplate eq 101" and the filter will apply.

It will include a few system document libraries, but otherwise shows just doc. libraries.

Also, be sure to include the subsite name in the URL prior to the /_api - e.g. https://yourdomain.sharepoint.com/subsite/_api/web/lists?$filter=BaseTemplate eq 101

1
  • Probably have been better to edit original or post a complete correct answer.
    – Nat
    Commented Mar 17, 2016 at 23:43
1

Add a Script Editor webpart into the page and paste below script inside it.

 <script   src="https://code.jquery.com/jquery-2.2.2.min.js"   integrity="sha256-36cp2Co+/62rEAAYHLmRCPIych47CvdM+uTBJwSzWjI="   crossorigin="anonymous"></script>

<div id="libraryList"><h2>Lists</h2><ul id='libraries'></ul></div>
<script language="javascript"> 

var siteUrl = window.location.protocol + "//" + window.location.host + _spPageContextInfo.webServerRelativeUrl;
jQuery.ajax({
    url: siteUrl + "/_api/web/lists?$filter=BaseTemplate eq 101",
    type: "GET",    
    headers: { 
        "accept": "application/json;odata=verbose",
        "content-type":"application/json;odata=verbose",
        "X-RequestDigest": jQuery("#__REQUESTDIGEST").val()
    },
    success: function(d) {
        var stringData = JSON.stringify(d);

        var jsonObject = JSON.parse(stringData);
        var results = jsonObject.d.results;

        for(i = 0; i < results.length;i++) {
            html += "<li><a href='" + siteUrl + results[i]["ParentWebUrl"]  + "'>" +  results[i]["Title"] + "</a></li>";
        }

        jQuery('#libraries').html(html)
    },
    error: function() {
        console.log('failed loading lists');
    }
});
</script>
3
  • I had to put <script language="javascript"> </script> Then I added the link to a hosted jQuery following this link sp365.co.uk/2011/07/adding-jquery-to-sharepoint Here's what it shows: Title appdata Composed Looks Content type publishing error log Converted Forms Documents Form Templates List Template Gallery Master Page Gallery MicroFeed Project Policy Item List Site Assets Site Pages Solution Gallery Style Library TaxonomyHiddenList Theme Gallery User Information List Web Part Gallery wfpub It doesn't show the doc libraries though :-\ Any suggestion? Thanks
    – gsandorx
    Commented Jan 13, 2015 at 23:37
  • I've been unable to get this to work in 2013. I get the header that says "List", but it's not showing the libraries within the site.
    – Carp
    Commented Oct 13, 2016 at 18:41
  • I got it to work in 2013. JS complains about an unintialised variable "html". You need to add a "var html = ""; just before the for loop.
    – Greg W
    Commented Jan 15, 2017 at 23:56

Your Answer

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

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