I try to order a Rest API query (SharePoint Online) via CSOM. Unfortunately it won't work. I want to get the files & folders of the rootfolder of a library sorted by name.

        url: baseUrl + "/_api/web/lists/getbytitle('" + projectLibraryName + "')/Rootfolder?$expand=Folders,Files,Files/ModifiedBy" +

Can somebody see why?

  • Are you getting any error message ?? – Rohit Waghela Jan 16 '18 at 15:22
  • No error message, I just get an unsorted result – mr.purzel Jan 16 '18 at 15:23
  • Try it with orderby=FileLeafRef and check ? – Gautam Sheth Jan 16 '18 at 15:24
  • 1
    orderby=FileLeafRef, same behaviour result is unsorted – mr.purzel Jan 16 '18 at 15:29
  • Can you check with /_api/Web/Lists/GetByTitle('"+ projectLibraryName +"')/Items?$select=FileLeafRef,FileRef,Editor/Name,Editor/EMail,EncodedAbsUrl,Modified&$expand=Editor,File,Folder&$orderby=FileLeafRef? I think it might solve your issue – Gautam Sheth Jan 16 '18 at 16:13

I had similar requirement to get all folders' names under root folder of "Help Documents" library, sorted by Name(default column). Below is the rest call I have used and it is working for me.

   function GetLinks() {
    var url = window.location.protocol + "//" + window.location.host + _spPageContextInfo.webServerRelativeUrl;
    var folderUrl = _spPageContextInfo.webServerRelativeUrl +"/Help Documents";
        url: url + "/_api/web/GetFolderByServerRelativeUrl('"+ folderUrl +"')/Folders?$select=ServerRelativeUrl,Name&$orderby=Name",
        type: "GET",
        async: false,
        headers: {
            "Accept": "application/json; odata=verbose"
        success: function(data) {
        error: function(data) {

Try the Rest below, order by Created Time:

_api/web/lists/getbyTitle('Jerrydoc')/Items?$select=FileLeafRef,FileRef,Created&$top=10&$order‌​by=Created desc

enter image description here

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.