In a SharePoint 2013 Document Library (version with x.x version enabled!) I have a PDF document, let's call it doc1.pdf which I want to replace by a new version.

The new document I have is called doc2.pdf .

I did not find a way yet to upload doc2.pdf and overwrite doc1.pdf. How can I do that?

It seems that I can only overwrite the existing document, if the new one has the same name as the existing one. ?!

4 Answers 4


Name the file you want to upload doc1.pdf. Go to "Upload" like you are adding a new file to the SharePoint folder. However, make sure the checkbox is selected "Add as a new version to existing files". This will overwrite the current doc1.pdf but keep your versioning.


I know this is not quite an answer you may be looking for, but why not rename doc2.pdf to doc1.pdf and then rename it in SharePoint itself?

  • 4
    Thanks! This looks like a very ugly workaround and is quite error-prone... :-(
    – mBBe
    Jul 10, 2014 at 14:39
  • 1
    We could do that if SharePoint told us that there was another document in that library with that same name. it doesn't there's the big problem. Thanks
    – user31437
    Jul 10, 2014 at 16:29

To avoid getting rid of data associated with the original file, you can open the file in "Open in Windows Explorer", then you can overwrite the file there. With a PDF, it maintains the ancillary information. CAUTION: It does NOT maintain with .doc files (which is annoying).


You can use the below code to update file content of existing file with new content and file name.

static void ReplaceFileContentWithNewFile(ClientContext context, string sourceLibraryName, int itemId, string newFilePath, string newFileName) {

  List sourceLibrary = context.Web.Lists.GetByTitle(sourceLibraryName);
  ListItem item = sourceLibrary.GetItemById(itemId);
  Microsoft.SharePoint.Client.File file = item.File;
  context.Load(item, i => i.File);

  using (FileStream fs = new FileStream(newFilePath, FileMode.Open, FileAccess.Read))
      var fileCreationInfo = new FileCreationInformation
          ContentStream = fs,
          Url = file.ServerRelativeUrl,
          Overwrite = true

      Microsoft.SharePoint.Client.File uploadFile = context.Web.RootFolder.Files.Add(fileCreationInfo);

  string newFileUrl = file.ServerRelativeUrl.Replace(file.Name, newFileName);
  file.MoveTo(newFileUrl, MoveOperations.Overwrite);


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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