Forum Discussion

Americo Perez's avatar
Americo Perez
Iron Contributor
May 09, 2018

Sharepoint Rest: Get library url

Hi,

How do I get the library URL? 

I tried with ServerRestUrl but I am getting undefined :-/ 

 

Best regards

Americo

  • I managed solve the url thing by creating it manually like this:

     

    hostweburl + '/' + this.Title

     

    But I noted another problem:

    In the site I have created 2 libraries "test" and "test2" but in the result, besides this 2 libraries, I am also getting system libraries like "MicroFeed", "appfiles", "appdata", etc. 

     

    I there a way to filter this system folder out? 

     

    This is how I am sending my request:

    url: appweburl + "/_api/SP.AppContextSite(@target)/web/lists?@target='" + hostweburl + "'"

    and later I am using this:

    $(results).each(function () {
    items.push('<li class="element">'
    + '<a target="_parent" href="' + hostweburl + '/' + this.Title + '">' + this.Title + '</a>'
    + '</li>');
    });

    Any tips??

     

    Americo 

    • Deleted's avatar
      Deleted

      The example above returns information about your file such as the name, full url and the internal “Title”:

      rest-select2

      For instances where you want to know the “type” of document library it is (example Picture Library vs Document Library), use:

      Although some information regarding document libraries require an entirely new endpoint. This includes file paths, subfolders, thumbnails and such.

      The above contains an entire new set of information regarding your library.

      • Americo Perez's avatar
        Americo Perez
        Iron Contributor

        Hi,

        Thanks!

         

        There is a little difference with the proposal you posted. I need to get the list of all libraries that is why I am using: 

        url: appweburl + "/_api/SP.AppContextSite(@target)/web/lists?@target='" + hostweburl + "'"

        without pointing to a specific library.

        The result I am getting doesn't contains "EncodedAbsUrl" in the respons.

        This is the response for one of the libraries:

         

         

        Best regards

        Americo

         

  • Shantha Kumar's avatar
    Shantha Kumar
    Brass Contributor

     

    Hi,

     

    If you are using SharePoint Online, you can try the below code for retrieving the Library URL,

     

    $.ajax({
            url: hostweburl + "/_api/web/AppTiles?$filter=BaseTemplate eq 101",
            method: "GET",
            headers: { "Accept": "application/json; odata=verbose" },
            success: function (response) {
                var libItems = "";
                $(response.d.results).each(function(){
                    libItems +="<li><a href='"+this.Target+"'>"+this.Title+"</a></li>";
                });
                $('#libitems').html(libItems);
                console.log(response);
            alert(response.d.results.length);
            },
            error: function (data) {
                failure(data);
            }
    });

    SharePoint Online returns the collection of lists, libraries and subsites under the below rest endpoint,

    https://<tenant>.sharepoint.com/_api/web/AppTiles

     

     Regards,

    Shantha Kumar T

Resources