3

I am using the following line of code to set the upload location for my file:

        var fileCollectionEndpoint = siteUrl + 
"/_api/web/getfolderbyserverrelativeurl('" + serverRelativeUrlToFolder + 
"')/files/add(overwrite=true,url='" + fileName + "')";

It works fine when uploading a document with a different name, however if I need to overwrite a document which already exists(has the same name) it throws an error saying the file already exists. Major versions are turned on in my document library and versioning/overwriting is working correctly when I use the out of the box default upload form!

Any ideas?

  • (overwrite=true,url='" + fileName + "')"; Need help with this. Would you pls tel what is fileName here. Is this the filename like "sample.png" – Guest Aug 17 '17 at 12:37
1

You could try this:

  1. Check if a file with the same name exists before uploading it
  2. if yes, asks the user if he/she wants to overwrite the existing file
  3. If yes, check out the existing file
  4. Upload your file
  5. (Optional) Check in the new uploaded file

Maybe it's the checkout step that you miss here?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.