2

I can copy a file from one site to another using

$SPFolder_Destination.Files.Add("Filename.ext", $SPFile_Source.OpenBinary(), $false)

This does not preserve version history.

I think I could possibly download all versions and then upload as new versions, but as you can see that is quite a mess.

Does anyone know any easier ways to transfer/copy a file between sites (on the same server) which maintains version history? I'm using SP2010.

Thanks.

3
  • Is it mandatory to use powershell? Can't you use server object model?
    – Aanchal
    Commented Jun 4, 2014 at 7:35
  • Forgive my ignorance, but doesn't Powershell use this object model anyway?
    – Sam
    Commented Jun 5, 2014 at 5:58
  • 1
    You can use the following PS script to copy/migrate files from one library to other . Please follow the guidelines and run ps with your server url. github.com/alimughalx/… Hopefully this may resolve your issue in case of PS. Please mark the answer if it helps you. Commented Sep 11, 2020 at 22:54

2 Answers 2

1

The behavior is by design, the version history of a document is relative to its original document library. When you move the document to another library, it is considered as a new document there, when the metadata is copied, it changes minor version. There is no Non-coding solution for this.

Also look at below blog to copy files with version history using Server side object model:

http://sharepointvenividivici.typepad.com/sharepoint-customization/2011/06/maintain-file-version-history-when-movingcopying-files-between-sharepoint-sites.html

You can try with its powershell equivalent code if you want to acheive this by powershell only.

1

The SPExportObject object and SPImport object seem to provide what I need.

This technet blog post provided the solution in C#, which I translated to Powershell.

Unfortunately at that point I ran into the same problems as the user in this post. Like him, I could not get the event handler to work correctly and like him, I bit the bullet and implemented the entire thing in C#.

It is now working (more or less) as desired.

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.