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.

5 Answers 5

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

2
  • 1
    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? Commented Mar 22, 2017 at 16:00
  • Add to your url the parameter: &$top=1000 Commented Apr 5, 2018 at 6: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>>
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.

1
  • Thanks, that filter is what I needed to restrict results to a specific folder. Commented Feb 12, 2024 at 19:50
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.

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

This URL will Resolve ur all problems

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.