121

Here's the scenario:

  1. 2 document libraries
  2. Both contain multiple documents
  3. The documents have multiple versions

When I copy a document from library A to Library B using the Content and Structure tool from Site Settings, my versions do not carry over. I'm trying to merge the two document libraries into one, but I want to retain the versions.

Do you know of a way to complete this without third party tools or custom code? I've heard suggestions of using Explorer View copy and paste, SharePoint Designer and List Templates, but I'm not sure any of those will carry version info.

Modern solution

For modern SharePoint experiences, use Move To.

Update 4/24/2018: There's a new solution in Office 365. You can now select a file or group of files in the modern experience in OneDrive or SharePoint and select Move to. A file or group of files moved this way will retain version history.

Update 6/6/2021: As @KJH mentioned in a comment, you may not see the modern experience unless you make a change to the library settings. Also, there's more detail now in the Microsoft article Move or copy files in SharePoint.

4
  • 2
    I don't know the answer to this and I've struggled with it, so I hope someone has a good thought that doesn't involve C# code! Commented Jan 28, 2010 at 0:18
  • I did as instructed and it DID NOT WORK. I moved the file and LOST my versions.
    – user9837
    Commented Aug 2, 2012 at 14:14
  • 2
    Is versioning on in the new library? @jaap points out in the comments on his answer, that he tried that and didn't lose the versions. When he moved it back to the original library the versions were retained.
    – Tom Resing
    Commented Aug 6, 2012 at 15:18
  • i also face this problem you but resolve it by using Csom Commented Jul 17, 2018 at 9:45

15 Answers 15

110

Just moved (drag & drop) a file in Explorer View from one document library to another, and it did retain previous versions!

Obviously both libraries need to have versioning enabled.

Try it yourself.

EDIT: note that it ONLY retains the versions if you MOVE the files. It does not do so when you perform a COPY!

18
  • 1
    Too obvious. We needed something harder. ;+) One thing to watch out for on this is that the documents are of the same Content Type. When they aren't, I've seen odd things happen. Commented Jan 31, 2010 at 19:44
  • 3
    if they are not of same CT, the CT will be copied with the document Commented Feb 1, 2010 at 8:26
  • 1
    It was second hand, but when items with different Content Types were copied, while the metadata went over just fine, the actual Content Types didn't. In other words, they weren't fully enabled on the destination. Commented Feb 2, 2010 at 13:34
  • 2
    Did you COPY the file? I MOVED them using drag & drop. Try that one. Commented Feb 3, 2010 at 11:59
  • 1
    Just tried a COPY instead of MOVE, and that did not retain the versions as mentioned by Tom. MOVE (drag & drop) does! Commented Feb 3, 2010 at 13:47
20

Last year I added functionality to Chris O'Brien's SharePoint Content Deployment Wizard to copy documents from one library to another. I'm pretty sure I tested that versioning copied over as well.

Have a try of that and if you have any problems using it please leave me a comment here and I'll update my answer with more info.

New Link : https://github.com/chrisdee/Tools/tree/master/SharePoint/SharePointContentDeploymentWizard

1
  • 1
    I am pretty sure this great tool does it. Just make sure to adjust the settings to get all versions of the document when copying it Commented Jan 29, 2010 at 8:30
18

As Anders mentions in his answer, my company SharePoint Products has a tool named CopyMove for just that. It is free to use for 1 named user - only organizations that need to offer the tool to their end-users will need to purchase a license.

The product can copy/move documents, list items and folders with no loss of metadata, version history and permissions. See the full feature matrix with screen shots here.

1
13

I know of no OOTB way to do this, so you would have to code this functionality yourself.

I know that Lars Fastrup has created a tool that does just what you want: CopyMove for SharePoint

It also has a web service API.

1
  • This link is now broken
    – Mark
    Commented Aug 26, 2016 at 17:29
12

a way to move documents through doc lib is to use the Content Deployment API.

using objects like SPExport and SPImport

the copy, move actions of the content site and structure (sitemanagement.aspx) are performed using this API.

and you can set that you want to keep the versions!

12

The Content and Structure worked fine for me. Moving individual documents from one library to another captures all versions. Assuming, of course, versioning is configured the same on both libraries. That bit me the first time - the destination had Major, but the source had Major/Minor. Once the destination was switched to Major/Minor, documents came over with all versions.

1
  • Thanks for the update @thantos. It's possible in the 4+ years since I posted this question that the functionality has been improved. Out of curiosity, what version and patch level did it work for you on? In January 2010, I was likely either using SharePoint 2007 SP2 or SharePoint 2010 RTM.
    – Tom Resing
    Commented Mar 31, 2014 at 16:07
11

Maybe helpful, in CodePlex:

Drag & Drop between SharePoint Document libraries

This project helps you to move documents by simply drag & drop the files between documents libraries out-of-the-box views located on the same web part page.Only SharePoint 2010 is supported.

… 

Current Limitations:

  • Document libraries should be in the same site.
  • Only default document library view is supported:
  • All views should have title.
  • All views should have summary toolbar.
  • All views should have the type and the name columns.
  • Only files with title can be moved.
  • You can’t drag folders or drop into folders.

Current Features:

  • Copy Operation has been added.
  • Folders are supported now.

Planned Features:

  • Delete Document by drag it to Recycle Bin.
  • Support Multiple Item Selection.
0
8

While I've noted above that I don't have a great answer, it's possible that SharePoint's Web Services with my jQuery Library for SharePoint Web Services may provide an answer. I had tried to do copies and preserve the metadata, but I couldn't quite get there. Perhaps it's worth another look. It certainly meets your "no code" requirement.

However, let me toss another idea into the mix: Do you really need to combine them? Might it work to provide views using a DVWP, or are you trying to get at something else?

1
  • DVWP is a good suggestion. I think in this case, it was just a matter of consolidating the two folders because they both were created redundantly.
    – Tom Resing
    Commented Feb 2, 2010 at 21:25
7

My problem was that I have an old 3.0 and I'm moving to Sharepoint online (office 365).

I downloaded Migration Suite For SharePoint from quest.com.

The problem I had with other migration tools is that I needed a domain to login. With this, it doesn't require it.

I was able to copy folders with contents, and the entire version history with comments was intact!

1
  • This would make a good comment, but it is not a good answer for the question, since I stated I wasn't looking for a 3rd party tool. Thanks for the input, though. Glad you found your solution!
    – Tom Resing
    Commented Oct 22, 2012 at 2:09
6

I always employ the drag and drop method suggested by Tom. Easiest enough for my end users to do themselves and I still have the version history.

6

For future reference: there's a legacy API used by SharePoint Designer, called FrontPage RPC, and there's a bunch of methods, including move document that accepts a put_option parameter with migrationsemantics flag to preserve the information about who created a document, who modified it, and when it was created, and this could be used from advanced workflow tools and custom components.

NB: The user must have administrative permissions or migrationsemantics is ignored.

5

Have you tried moving the document using the Content and Structure option in site settings? I don't recall if this works or not.

3
  • 3
    Please read the question. That is the first thing I tried.
    – Tom Resing
    Commented Jan 29, 2010 at 14:49
  • 1
    @TomResing sorry to revive such an old post, but it looks like this answer may have actually been right after all, specifically because it mentions moving the document as opposed to the line from your question When I copy a document from library A to Library B using the Content and Structure tool. The reason I'm commenting is, as Kolten mentions on Jaap's answer, drag-and-drop move in Explorer view changes the "Modified by" metadata of all version to that of the user performing the move. I'm wondering if using Content and Structure to do the move would preserve metadata and versions. Commented Aug 18, 2015 at 20:05
  • Just saw this thread now. Moving using content & structure do preserve version history and is the best OOTB option to move data with version history as it works with lists & libraries
    – Unnie
    Commented Apr 20, 2017 at 10:45
5

Our method was uploading the infopath form to the destination libary and deselecting "Enable this form to be filled out by using a browser". This way the content types in the from library matched the content types in the to library.

5

There's a new solution in Office 365.

You can now select a file or group of files in the modern experience in OneDrive or SharePoint and select Move to. A file or group of files moved this way will retain version history.

This change is currently marked "Rolling Out" on the Office 365 Roadmap and their are more details about the roll-out schedule on the Microsoft Tech Community.

2
  • 1
    I'd like to add my +1 to this (Modern experience) as I originally glossed over the OP's mention of this. It's at least an order of magnitude better than the Classic experience. Here's a howto: support.microsoft.com/en-us/office/… NOTE that you may not have the permissions to modify this and will have to ask your SP admin.
    – KJH
    Commented Jun 5, 2021 at 12:02
  • 1
    Good point @KJH! I've edited the question to make the modern solution more obvious and added a note about switching to modern and the link you recommended.
    – Tom Resing
    Commented Jun 6, 2021 at 16:51
4
//To move file from source library to destination through Event handler

SPFile sourceFile = properties.ListItem.File;
SPFile destFile = null;
SPUser userCreatedBy = sourceFile.Author;
DateTime dateCreatedOn = sourceFile.TimeCreated.ToLocalTime();
int countVersions = properties.ListItem.File.Versions.Count;
for (int i = 0; i <= countVersions; i++)
{
    Hashtable hashSourceProp;
    SPFileStream streamFile;
    SPUser userModifiedBy;
    DateTime dateModifiedOn;
    string strVerComment = "";
    bool bolMajorVer = false;
    if (i < countVersions)
    {
        SPFileVersion fileSourceVer = properties.ListItem.File.Versions[i];
        hashSourceProp = fileSourceVer.Properties;
        userModifiedBy = (i == 0) ? userCreatedBy : fileSourceVer.CreatedBy;
        dateModifiedOn = fileSourceVer.Created.ToLocalTime();
        strVerComment = fileSourceVer.CheckInComment;
        bolMajorVer = fileSourceVer.VersionLabel.EndsWith("0") ? true : false;
        streamFile = (SPFileStream)fileSourceVer.OpenBinaryStream();
    }
    else
    {
        /*Here I'm getting the information for the current version.  Unlike in SPFileVersion when I get the modified date from SPFile it's already in local time.*/
        userModifiedBy = sourceFile.ModifiedBy;
        dateModifiedOn = sourceFile.TimeLastModified;
        hashSourceProp = sourceFile.Properties;
        strVerComment = sourceFile.CheckInComment;
        bolMajorVer = sourceFile.MinorVersion == 0 ? true : false;
        streamFile = (SPFileStream)sourceFile.OpenBinaryStream();
    }                              
        SPDocumentLibrary destLib = (SPDocumentLibrary)properties.ListItem.Web.Lists["Destination ListName"];                                   
         destFile = destLib.RootFolder.Files.Add(sourceFile.Name, streamFile, hashSourceProp, userCreatedBy,
         userModifiedBy,
         dateCreatedOn,
         dateModifiedOn,
         strVerComment,
         true);
}  
properties.Web.AllowUnsafeUpdates = true;
SPList documentLibraryAsList = properties.Web.Lists["Destination ListName"];
//To update other fields in destination docuemnt Library
SPListItem itemJustAdded = documentLibraryAsList.GetItemById(destFile.ListItemAllFields.ID);        
itemJustAdded["Column Name] = "Any Status"; 
//Update Terms
TaxonomyField column = itemJustAdded.Fields.GetField("Tags") as TaxonomyField;
TaxonomyFieldValueCollection taxFieldValueColl = properties.ListItem["Tags"] as TaxonomyFieldValueCollection;
if (taxFieldValueColl.Count > 0)
{
    if (taxFieldValueColl.Count == 1)
    {
        column.SetFieldValue(itemJustAdded, taxFieldValueColl.First());
    }
    else
    {
    column.SetFieldValue(itemJustAdded, taxFieldValueColl);
    }
    column.Update();
}                           
itemJustAdded.Update();                                                     
properties.Web.AllowUnsafeUpdates = false;  

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