Sharepoint API to create a file

priyanka konakalla 0 Reputation points
2024-06-24T12:58:18.07+00:00

Hi

I would like to consume Sharepoint API.I have a question will the Sharepoint API to create a file always overrides the file if the file with same name already exists.

As I see in the syntax below overwrite = true

https://{site_url}/_api/web/GetFolderByServerRelativeUrl('Folder Name')/Files/add(url='a.txt',overwrite=true)

Microsoft 365 and Office | SharePoint | For business | Windows
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Emily Du-MSFT 51,946 Reputation points Microsoft External Staff
    2024-06-25T06:46:15.2666667+00:00

    I have tested the Rest API https://{site_url}/_api/web/GetFolderByServerRelativeUrl('Folder Name')/Files/add(url='a.txt',overwrite=true). When you set parament overwrite=true, the newly created file will override the file with same name already exists.

    File created before:

    1

    File created new:

    2


    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' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.