none
Get top 3 files from Folder in SharePoint 2013 using REST api

    Question

  • I am currently working on a query to get top 3 files from SharePoint document library which has folders within a folders structure. I am currently using below query 

    http://siteurl/_api/web/GetFolderByServerRelativeUrl('libraryname/folder1/folder2')/Files?$expand=ListItemAllFields,Author/ID,ListItemAllFields/FieldValuesAsText,ListItemAllFields/Published_x0020_Date&$orderby=ListItemAllFields/Published_x0020_Date%20desc&$top=3

    The above query works fine without $orderby. When I add $orderby it throws below exception 

    <m:error xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata">
    <m:code>
    -1, Microsoft.SharePoint.Client.InvalidClientQueryException
    </m:code>
    <m:message xml:lang="en-US">
    Field or property "Published_x0020_Date" does not exist.
    </m:message>
    </m:error>

    Does anyone has any idea why this is not working?

    Any help is appreciated.


    Rishi!

    jeudi 7 juin 2018 23:35

Réponses

  • Hi Rishi,

    I could reproduce this issue on my environment(15.0.4989.1001), I also tested on SharePoint Online, it could work well.

    As a workaround, you can use the following REST API:

    http://sp13/sites/test1/_api/web/lists/getbytitle('Doc_anthour')/items?$select=ID,FileRef,Created,Author/ID&$expand=Author&$orderby=Published_x0020_Date desc&$filter=substringof('Doc_anthour/Test',FileRef) 

    Note: please remember to change the library name and folder name in the above REST API.

    Or, you can try to install latest CU for your SharePoint farm, then test again.

    Thanks,

    Wendy


    Please remember to mark the replies as answers if they helped. If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com.


    Click here to learn more. Visit the dedicated forum to share, explore and talk to experts about Microsoft Teams.

    vendredi 8 juin 2018 08:11
    Modérateur

Toutes les réponses

  • Hi Rishi,

    I could reproduce this issue on my environment(15.0.4989.1001), I also tested on SharePoint Online, it could work well.

    As a workaround, you can use the following REST API:

    http://sp13/sites/test1/_api/web/lists/getbytitle('Doc_anthour')/items?$select=ID,FileRef,Created,Author/ID&$expand=Author&$orderby=Published_x0020_Date desc&$filter=substringof('Doc_anthour/Test',FileRef) 

    Note: please remember to change the library name and folder name in the above REST API.

    Or, you can try to install latest CU for your SharePoint farm, then test again.

    Thanks,

    Wendy


    Please remember to mark the replies as answers if they helped. If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com.


    Click here to learn more. Visit the dedicated forum to share, explore and talk to experts about Microsoft Teams.

    vendredi 8 juin 2018 08:11
    Modérateur
  • Where do I need to specify the folder name in the query? I see the list/library name. I need to go deep into the folders and get the files from specific folder.

    Rishi!

    vendredi 8 juin 2018 18:25
  • It seems to be working fine but this query is taking more time than other query.

    Rishi!

    vendredi 8 juin 2018 22:01