2

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 !

  • You can easily achieve this using JavaScript and REST API. – Amal Hashim Jan 13 '15 at 22:42
  • Do do you have more info about this? Maybe a sample code snippet? Thanks ! – gsandorx Jan 13 '15 at 22:59
  • gsandorx: Check my answer. – Amal Hashim Jan 13 '15 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? – Jesus Shelby Jan 14 '15 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 Jan 15 '15 at 18:11
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

| improve this answer | |
  • Probably have been better to edit original or post a complete correct answer. – Nat Mar 17 '16 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>
| improve this answer | |
  • 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 Jan 13 '15 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 Oct 13 '16 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 Jan 15 '17 at 23:56

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.