Share via

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

g h 716 Reputation points
2020-12-18T07:15:44.747+00:00

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 ?

Microsoft 365 and Office | SharePoint Server | Development
0 comments No comments

Answer accepted by question author

ZhengyuGuo 10,591 Reputation points Moderator
2020-12-21T02:18:58.283+00:00

Hi @g h ,

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.

Was this answer helpful?

10+ people found this answer helpful.
0 comments No comments

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.