Files Archives : Binary Bits https://blog.binarybits.net/tag/files/ Bits & Pieces - A blog by Kannan Balasubramanian Fri, 20 Dec 2019 07:33:48 +0000 en-GB hourly 1 https://wordpress.org/?v=6.5.2 Get folder and files recursively in SharePoint using REST call https://blog.binarybits.net/get-folder-and-files-recursively-in-sharepoint-using-rest-call/ https://blog.binarybits.net/get-folder-and-files-recursively-in-sharepoint-using-rest-call/#respond Tue, 25 Sep 2018 10:14:22 +0000 https://blog.binarybits.net/?p=988 There was a simple requirement I came across for which a page should list all the files and folders in a SharePoint document library. I came up with a solution using ODATA call. Following is the REST call I made to get the list of all folder and files. /_api/web/Lists/GetByTitle(‘Documents’)/Items?$select=FileLeafRef,FileRef&$orderby=FileRef asc Following is the code […]

The post Get folder and files recursively in SharePoint using REST call appeared first on Binary Bits.

]]>
There was a simple requirement I came across for which a page should list all the files and folders in a SharePoint document library.

I came up with a solution using ODATA call. Following is the REST call I made to get the list of all folder and files.

/_api/web/Lists/GetByTitle(‘Documents’)/Items?$select=FileLeafRef,FileRef&$orderby=FileRef asc

Following is the code which quickly prints them out in a table. Just add this code to a script editor web-part.
Please make sure the URL is updated based on your site URL.

<script src="//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<script type="text/javascript">
    $.ajax({
        url: "<site url>/_api/web/Lists/GetByTitle('Documents')/Items?$select=FileLeafRef,FileRef&$orderby=FileRef asc",
        type: "GET",
        headers: {
            "Accept": "application/json;odata=verbose"
        },
        success: function (data, textStatus, xhr)
        {
            $.each(data.d.results, function (index, item)
            {
                // alert("The items in list are : " + item.FileRef);
                $("#table1 tbody").append("<tr><td>" + item.FileRef + "</td></tr>");
            })
        },
        error: function r(xhr, textStatus, errorThrown)
        {
            alert("error:" + JSON.stringify(xhr));
        }
    });
</script>

<table id="table1">
    <tbody></tbody>
</table>

The post Get folder and files recursively in SharePoint using REST call appeared first on Binary Bits.

]]>
https://blog.binarybits.net/get-folder-and-files-recursively-in-sharepoint-using-rest-call/feed/ 0