0

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" +
            "&$select=Files/ModifiedBy/Title,Files/ModifiedBy/Email,Files/Name,Files/TimeLastModified,Files/ServerRelativeUrl,Folders/Name,Folders/TimeLastModified,Folders/ServerRelativeUrl"+
            "&$orderby=Folders/Name,Files/Name",

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
1

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";
    $.ajax({
        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) {
        alert(JSON.stringify(data));
        alert(data.d.results[0].Name);
        alert(data.d.results[1].Name);
        },
        error: function(data) {
            console.log(JSON.stringify(data));
        }
    });
  }
0

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.