https://<Site_URL>/_api/web/GetFileByServerRelativeUrl('/Folder Name/{file'name}')/$value return 400 (Bad request) when the filename contains a single quote

Sudhakar 20 Reputation points
2025-03-26T09:57:39.4666667+00:00

Hello,

I'm calling the below SharePoint API where file name contains the single quate (') into the name & getting 400 error.

URL- https://<Site_URL>/_api/web/GetFileByServerRelativeUrl('/SudDammyDocLib/DocLib_Folder/issue's.aspx')/$value
File Name: issue's.aspx

400BadRequest

Could you please tell us why error coming & how to fix it.

https://learn.microsoft.com/en-us/sharepoint/dev/sp-add-ins/working-with-folders-and-files-with-rest#working-with-files-by-using-rest

SharePoint Server Development
SharePoint Server Development
SharePoint Server: A family of Microsoft on-premises document management and storage systems.Development: The process of researching, productizing, and refining new or existing technologies.
1,655 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. RaytheonXie_MSFT 40,451 Reputation points Microsoft External Staff
    2025-03-27T02:11:15.9266667+00:00

    Hi @Sudhakar

    Try putting extra apostrophe and replace ' with ". In your case the url should be like following

    https://<Site_URL>/_api/web/GetFileByServerRelativeUrl("/SudDammyDocLib/DocLib_Folder/issue''s.aspx")/$value
    
    
    

    If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    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.


Your answer

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