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.

Sam
  • 131
  • 1
  • 6
  • Is it mandatory to use powershell? Can't you use server object model? – Aanchal Jun 04 '14 at 07:35
  • Forgive my ignorance, but doesn't Powershell use this object model anyway? – Sam Jun 05 '14 at 05: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. https://github.com/alimughalx/CopySharePointFilesWithMetaDataAndVersionHistory Hopefully this may resolve your issue in case of PS. Please mark the answer if it helps you. – ALI RAZA ZAFAR Sep 11 '20 at 22:54

2 Answers2

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.

Aanchal
  • 7,885
  • 1
  • 15
  • 20
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.

Sam
  • 131
  • 1
  • 6