5

Currently I am using REST in order to get item titles in the Pages directory. The problem is that it is pulling all the elements that are in the pages directory and I only want it to pull from a certain subfolder in the pages directory.

var moduleServiceUrl = _spPageContextInfo.webAbsoluteUrl + "/_api/lists/getbytitle('Pages')/Items?$select=ID,Title,FileRef,Modules";

This is what the call currently looks like.

user60232
  • 59
  • 1
  • 1
  • 2

5 Answers5

11

Try to use this endpoint GetFolderByServerRelativeUrl to return all files and folder at a specific folder URL

https://server/_api/Web/GetFolderByServerRelativeUrl(<folder url>)?$expand=Folders,Files

To return only all files at a specific folder URL

https://server/_api/Web/GetFolderByServerRelativeUrl(<folder url>)?$expand=Files

For more details check get all the files and folders contained inside a SharePoint folder in one rest API call.

Also if you need work with CSOM check How to get all the files inside the folder in list

Mohamed El-Qassas MVP
  • 45,382
  • 9
  • 53
  • 96
  • It only retrieves the first 100 and includes a link to "next 100" Is there any way to pull everything in the list without pagination? – Si8 Mar 22 '17 at 16:00
  • Add to your url the parameter: &$top=1000 – Oskar Apr 05 '18 at 06:57
1

The query you are using will return all items irrespective of type (folder/file). You can use change to below syntax.

_spPageContextInfo.webAbsoluteUrl + "/_api/web/getfolderbyserverrelativeurl('<<folder relative path>>')/Files

Example for folder relative path is

/[subsite]/<<library name>>/<<folder name>>
Venkat Konjeti
  • 4,959
  • 1
  • 10
  • 19
1

You can try using:

_api/web/Lists/GetByTitle('{listTitle}')/Items?$filter=FileDirRef eq '{serverRelativeUrl}'

However it will only give items from the specific folder.

This query:

_api/web/Lists/GetByTitle('{listTitle}')/Items?$filter=startswith(FileDirRef, '{serverRelativeUrl}')

should return items from other sub folders also.

Beniamin
  • 131
  • 4
0

I don't fully understand what you need but in order to get attributes of a subfolder you need to access the folder first through this endpoint GetFolderByServerRelativeUrl.

Here is a Microsoft documentation regarding Files and folders REST API call.

iambvttercvp
  • 91
  • 2
  • 12
-1
_spPageContextInfo.webAbsoluteUrl + "/_api/Lists/getbyTitle('" + LibraryName + "')/Items?$select=FileLeafRef,FileRef,Id&$top=5000

This URL will Resolve ur all problems

Dikesh Gandhi
  • 6,803
  • 4
  • 30
  • 55
Negi Rox
  • 211
  • 3
  • 9