locked
Copy Files together with version history RRS feed

  • Question

  • Well.. doer anyone know if it is possible to copy a SPFile between lists using the SharePoint object model? The thing is I need to keep all of the file's version history intact. As I know it, there is no built in WSS function to achieve this.

     

    Anyone?

    Wednesday, October 31, 2007 2:35 PM

Answers

All replies

  • Well.. No replies. It seems this is not possible, at least to my knowledge.

    SPFile.CopyTo does not keep versions history, it only copies the most recent copy. Custom code is requried to copy versions.

    SPFile.MoveTo moves the file and keeps history.

     

    Thursday, November 15, 2007 8:57 AM
  • No it isn't possible OOB. We ended by wirting our own copy/move tool to deal with this issue. Also SPFile.MoveTo seems to work in the same Site (SPWeb) only.
    Thursday, November 15, 2007 12:44 PM
  • I have a custom stsadm command that I created which could be abstracted out to use independently: http://stsadm.blogspot.com/.  The command is copylistitem but it had a delete option to make it work like a move.  If you pull down the code you  could probably easily pull the pieces you need out in order to create a move method.

    Friday, November 16, 2007 2:28 AM
  •  

    I actually just posted an article on how to do this the other day:

    http://www.sharepointblogs.com/dez/archive/2007/11/30/moving-copying-documents-between-libraries-with-metadata-including-version-history.aspx

     

    Hopefully it will help,

     

    - dink

    Tuesday, December 11, 2007 10:16 PM
  • Great article! Very nice write-up!

     

    I've got only two questions:

    1. Why didn't you use SPFile.Versions once you get the file? And the you could add the versions in reverse order to the required folder, using one of the overloads of SPFolder.Add()..

     

    2. Did you consider using SPExport/SPImport on item level for the export? I don't know how suitable it is on item level, but it cetainly is better that a custom solution to export lists and whole sites! You mentioned you want to do this in the comments to your article...

     

    Thursday, December 13, 2007 5:06 PM
  • I replied to you on my blog.

     

    - Dink

     

    Tuesday, December 18, 2007 9:34 PM