如何將帶有版本歷史記錄的文檔移動到新庫中?


118

這是場景:

  1. 2個文檔庫
  2. 兩者都包含多個文檔
  3. 文檔有多個版本

當我使用"站點設置"中的"內容和結構"工具將文檔從庫A複製到庫B時,我的版本不會保留。我試圖將兩個文檔庫合併為一個,但是我想保留版本。

您知道沒有第三方工具或自定義代碼即可完成此操作的方法嗎?我聽說過有關使用資源管理器視圖複製和粘貼,SharePoint Designer和列表模板的建議,但我不確定其中是否會包含版本信息。

更新4/24/2018 :Office 365中有一個新的解決方案。您現在可以在OneDrive或SharePoint中以現代體驗選擇一個文件或一組文件,然後選擇"移至"。以這種方式移動的文件或文件組將保留版本歷史記錄。

更新1/29/2010 :感謝所有代碼建議。它們可以滿足其他需求,但是,我想強調的是,這是無代碼部署的情況。想想BPOS。

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.


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.


21

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


19

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.


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?


109

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!


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!


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.

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!


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.


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

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.


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;  

4

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.