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)

SharePoint
SharePoint
A group of Microsoft Products and technologies used for sharing and managing content, knowledge, and applications.
10,140 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Emily Du-MSFT 43,431 Reputation points Microsoft Vendor
    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.