Saturday, February 21, 2015

In last article we saw how to get top level folders. Now lets see how to get all SharePoint library files from the root folder or top level folders using SharePoint REST API. Using REST services you can get files of library. in this article we will see how to get files at top level or from Root folder. We will see how to fetch files within folders in coming article.

Following is the URL to get files :


The only difference with folder URL is that it replaces 'folders' by 'files'.

Following is the sample code:

<script src="/Site%20Assets/js/jquery-1.11.1.min.js"></script>
function GetAllFoldersofRootFolders()
                url: "/_api/web/lists/getbytitle('test1')/RootFolder/files",     
                method: "GET",
                headers: {
                                "ACCEPT": "application/json;odata=verbose",
                                "content-type": "application/json;odata=verbose"                         
                success: function (data) {
                                var htmlStr = "";
                                $.each(data.d.results, function(){
                                                if(htmlStr === "")
                                                                htmlStr = "<li 'ServerRelativeUrl="+ this.ServerRelativeUrl + "'>"  + this.Name + “</li>";
                                                                htmlStr = htmlStr + "<li 'ServerRelativeUrl="+ this.ServerRelativeUrl + "'>"  + this.Name + “</li>";
                error: function (data) {
                                alert("Error occured." + data);


                <input type="submit" onclick="GetAllFoldersofRootFolders()" value="Get All Folders of Root folder"> </input>

                <ul id="foldersDiv">

Happy SharePoint coding. 


Post a Comment