1

I have a document library which may have folders in it. I want to get the most recently uploaded files (say latest 10 files) using REST API, irrespective of which folders they are uploaded to.

I can get the latest files in root folder by using below URL.

http://<SERVER>/_api/web/GetFolderByServerRelativeUrl('/<DOCUMENT LIBRARY>')/files?$select=Name,TimeCreated&$orderby=TimeCreated%20desc

But it does not include any files uploaded to folders in the document library.

How can I achieve this? I am open to using client object model also.

2

You can use the below REST endpoint:

http://<SERVER>/_api/web/lists/GetByTitle('Documents')/items?
$filter=ContentType eq 'Document'
&$select=Title,FileLeafRef,Created,EncodedAbsUrl
&$orderby=Created desc&$top=10

This will give you latest 10 uploaded documents along with the document's title, name, absolute url as well as created date. This assumes that you know the list name.

  • you can also specify filter as $filter=ContentType ne 'Folder' which will exclude the folders – Gautam Sheth Nov 15 '17 at 6:59

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.