question

gh-2449 avatar image
0 Votes"
gh-2449 asked Jerryzy answered

GetFolderByServerRelativeUrl Rest API return Server relative urls must start with SPWeb.ServerRelativeUrl

I am trying to fetch all files from a folder in SharePoint. I am looking for all file stored under "Shared%20Ducuments" path:

https://{server_name}/sites/{sub_site}/_api/web/GetFolderByServerRelativeUrl('/Shared%20Documents')/Files

Return this error:

 <m:code>-2147024809, System.ArgumentException</m:code>
     <m:message xml:lang="en-US">Server relative urls must start with SPWeb.ServerRelativeUrl</m:message>

Can anyone help please ?

office-sharepoint-server-development
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

Jerryzy avatar image
3 Votes"
Jerryzy answered

Hi @gh-2449,

Please modify the Rest EndPoint like below:

 https://{server_name}/sites/{sub_site}/_api/web/GetFolderByServerRelativeUrl('/sites/sub_site/Shared%20Documents')/Files

The ServerRelativeUrl needs to prepend /sites/sitename.

Thanks
Best Regards


If an Answer is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.