{"id":988,"date":"2018-09-25T15:44:22","date_gmt":"2018-09-25T10:14:22","guid":{"rendered":"https:\/\/blog.binarybits.net\/?p=988"},"modified":"2019-12-20T13:03:48","modified_gmt":"2019-12-20T07:33:48","slug":"get-folder-and-files-recursively-in-sharepoint-using-rest-call","status":"publish","type":"post","link":"https:\/\/blog.binarybits.net\/get-folder-and-files-recursively-in-sharepoint-using-rest-call\/","title":{"rendered":"Get folder and files recursively in SharePoint using REST call"},"content":{"rendered":"\n

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

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.<\/p>\n\n\n\n

\/_api\/web\/Lists\/GetByTitle(‘Documents’)\/Items?$select=FileLeafRef,FileRef&$orderby=FileRef asc<\/p><\/blockquote>\n\n\n\n

Following is the code which quickly prints them out in a table. Just add this code to a script editor web-part.
\nPlease make sure the URL is updated based on your site URL.<\/p>\n\n\n\n

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

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 […]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"inline_featured_image":false,"footnotes":""},"categories":[62],"tags":[273,272,274,150,208],"yoast_head":"\nGet folder and files recursively in SharePoint using REST call : Binary Bits<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/blog.binarybits.net\/get-folder-and-files-recursively-in-sharepoint-using-rest-call\/\" \/>\n<meta property=\"og:locale\" content=\"en_GB\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Get folder and files recursively in SharePoint using REST call : Binary Bits\" \/>\n<meta property=\"og:description\" content=\"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 […]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/blog.binarybits.net\/get-folder-and-files-recursively-in-sharepoint-using-rest-call\/\" \/>\n<meta property=\"og:site_name\" content=\"Binary Bits\" \/>\n<meta property=\"article:published_time\" content=\"2018-09-25T10:14:22+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2019-12-20T07:33:48+00:00\" \/>\n<meta name=\"author\" content=\"Kannan\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@Kannan_B\" \/>\n<meta name=\"twitter:site\" content=\"@Kannan_B\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Kannan\" \/>\n\t<meta name=\"twitter:label2\" content=\"Estimated reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"1 minute\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/blog.binarybits.net\/get-folder-and-files-recursively-in-sharepoint-using-rest-call\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/blog.binarybits.net\/get-folder-and-files-recursively-in-sharepoint-using-rest-call\/\"},\"author\":{\"name\":\"Kannan\",\"@id\":\"https:\/\/blog.binarybits.net\/#\/schema\/person\/dda0e26212583a95f286cf67604fd855\"},\"headline\":\"Get folder and files recursively in SharePoint using REST call\",\"datePublished\":\"2018-09-25T10:14:22+00:00\",\"dateModified\":\"2019-12-20T07:33:48+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/blog.binarybits.net\/get-folder-and-files-recursively-in-sharepoint-using-rest-call\/\"},\"wordCount\":105,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/blog.binarybits.net\/#\/schema\/person\/dda0e26212583a95f286cf67604fd855\"},\"keywords\":[\"Files\",\"Folders\",\"jQuery\",\"REST\",\"SharePoint\"],\"articleSection\":[\"SharePoint\"],\"inLanguage\":\"en-GB\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/blog.binarybits.net\/get-folder-and-files-recursively-in-sharepoint-using-rest-call\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/blog.binarybits.net\/get-folder-and-files-recursively-in-sharepoint-using-rest-call\/\",\"url\":\"https:\/\/blog.binarybits.net\/get-folder-and-files-recursively-in-sharepoint-using-rest-call\/\",\"name\":\"Get folder and files recursively in SharePoint using REST call : Binary Bits\",\"isPartOf\":{\"@id\":\"https:\/\/blog.binarybits.net\/#website\"},\"datePublished\":\"2018-09-25T10:14:22+00:00\",\"dateModified\":\"2019-12-20T07:33:48+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/blog.binarybits.net\/get-folder-and-files-recursively-in-sharepoint-using-rest-call\/#breadcrumb\"},\"inLanguage\":\"en-GB\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/blog.binarybits.net\/get-folder-and-files-recursively-in-sharepoint-using-rest-call\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/blog.binarybits.net\/get-folder-and-files-recursively-in-sharepoint-using-rest-call\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/blog.binarybits.net\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Get folder and files recursively in SharePoint using REST call\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/blog.binarybits.net\/#website\",\"url\":\"https:\/\/blog.binarybits.net\/\",\"name\":\"Binary Bits\",\"description\":\"Bits & Pieces - A blog by Kannan Balasubramanian\",\"publisher\":{\"@id\":\"https:\/\/blog.binarybits.net\/#\/schema\/person\/dda0e26212583a95f286cf67604fd855\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/blog.binarybits.net\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-GB\"},{\"@type\":[\"Person\",\"Organization\"],\"@id\":\"https:\/\/blog.binarybits.net\/#\/schema\/person\/dda0e26212583a95f286cf67604fd855\",\"name\":\"Kannan\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-GB\",\"@id\":\"https:\/\/blog.binarybits.net\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/blog.binarybits.net\/wp-content\/uploads\/2017\/04\/12976869_10207528235497646_1307827709790943986_o.jpg\",\"contentUrl\":\"https:\/\/blog.binarybits.net\/wp-content\/uploads\/2017\/04\/12976869_10207528235497646_1307827709790943986_o.jpg\",\"width\":1270,\"height\":1270,\"caption\":\"Kannan\"},\"logo\":{\"@id\":\"https:\/\/blog.binarybits.net\/#\/schema\/person\/image\/\"}}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Get folder and files recursively in SharePoint using REST call : Binary Bits","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/blog.binarybits.net\/get-folder-and-files-recursively-in-sharepoint-using-rest-call\/","og_locale":"en_GB","og_type":"article","og_title":"Get folder and files recursively in SharePoint using REST call : Binary Bits","og_description":"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 […]","og_url":"https:\/\/blog.binarybits.net\/get-folder-and-files-recursively-in-sharepoint-using-rest-call\/","og_site_name":"Binary Bits","article_published_time":"2018-09-25T10:14:22+00:00","article_modified_time":"2019-12-20T07:33:48+00:00","author":"Kannan","twitter_card":"summary_large_image","twitter_creator":"@Kannan_B","twitter_site":"@Kannan_B","twitter_misc":{"Written by":"Kannan","Estimated reading time":"1 minute"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/blog.binarybits.net\/get-folder-and-files-recursively-in-sharepoint-using-rest-call\/#article","isPartOf":{"@id":"https:\/\/blog.binarybits.net\/get-folder-and-files-recursively-in-sharepoint-using-rest-call\/"},"author":{"name":"Kannan","@id":"https:\/\/blog.binarybits.net\/#\/schema\/person\/dda0e26212583a95f286cf67604fd855"},"headline":"Get folder and files recursively in SharePoint using REST call","datePublished":"2018-09-25T10:14:22+00:00","dateModified":"2019-12-20T07:33:48+00:00","mainEntityOfPage":{"@id":"https:\/\/blog.binarybits.net\/get-folder-and-files-recursively-in-sharepoint-using-rest-call\/"},"wordCount":105,"commentCount":0,"publisher":{"@id":"https:\/\/blog.binarybits.net\/#\/schema\/person\/dda0e26212583a95f286cf67604fd855"},"keywords":["Files","Folders","jQuery","REST","SharePoint"],"articleSection":["SharePoint"],"inLanguage":"en-GB","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/blog.binarybits.net\/get-folder-and-files-recursively-in-sharepoint-using-rest-call\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/blog.binarybits.net\/get-folder-and-files-recursively-in-sharepoint-using-rest-call\/","url":"https:\/\/blog.binarybits.net\/get-folder-and-files-recursively-in-sharepoint-using-rest-call\/","name":"Get folder and files recursively in SharePoint using REST call : Binary Bits","isPartOf":{"@id":"https:\/\/blog.binarybits.net\/#website"},"datePublished":"2018-09-25T10:14:22+00:00","dateModified":"2019-12-20T07:33:48+00:00","breadcrumb":{"@id":"https:\/\/blog.binarybits.net\/get-folder-and-files-recursively-in-sharepoint-using-rest-call\/#breadcrumb"},"inLanguage":"en-GB","potentialAction":[{"@type":"ReadAction","target":["https:\/\/blog.binarybits.net\/get-folder-and-files-recursively-in-sharepoint-using-rest-call\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/blog.binarybits.net\/get-folder-and-files-recursively-in-sharepoint-using-rest-call\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/blog.binarybits.net\/"},{"@type":"ListItem","position":2,"name":"Get folder and files recursively in SharePoint using REST call"}]},{"@type":"WebSite","@id":"https:\/\/blog.binarybits.net\/#website","url":"https:\/\/blog.binarybits.net\/","name":"Binary Bits","description":"Bits & Pieces - A blog by Kannan Balasubramanian","publisher":{"@id":"https:\/\/blog.binarybits.net\/#\/schema\/person\/dda0e26212583a95f286cf67604fd855"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/blog.binarybits.net\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-GB"},{"@type":["Person","Organization"],"@id":"https:\/\/blog.binarybits.net\/#\/schema\/person\/dda0e26212583a95f286cf67604fd855","name":"Kannan","image":{"@type":"ImageObject","inLanguage":"en-GB","@id":"https:\/\/blog.binarybits.net\/#\/schema\/person\/image\/","url":"https:\/\/blog.binarybits.net\/wp-content\/uploads\/2017\/04\/12976869_10207528235497646_1307827709790943986_o.jpg","contentUrl":"https:\/\/blog.binarybits.net\/wp-content\/uploads\/2017\/04\/12976869_10207528235497646_1307827709790943986_o.jpg","width":1270,"height":1270,"caption":"Kannan"},"logo":{"@id":"https:\/\/blog.binarybits.net\/#\/schema\/person\/image\/"}}]}},"_links":{"self":[{"href":"https:\/\/blog.binarybits.net\/wp-json\/wp\/v2\/posts\/988"}],"collection":[{"href":"https:\/\/blog.binarybits.net\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.binarybits.net\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.binarybits.net\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.binarybits.net\/wp-json\/wp\/v2\/comments?post=988"}],"version-history":[{"count":3,"href":"https:\/\/blog.binarybits.net\/wp-json\/wp\/v2\/posts\/988\/revisions"}],"predecessor-version":[{"id":1077,"href":"https:\/\/blog.binarybits.net\/wp-json\/wp\/v2\/posts\/988\/revisions\/1077"}],"wp:attachment":[{"href":"https:\/\/blog.binarybits.net\/wp-json\/wp\/v2\/media?parent=988"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.binarybits.net\/wp-json\/wp\/v2\/categories?post=988"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.binarybits.net\/wp-json\/wp\/v2\/tags?post=988"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}