kwizcom banner advertisement

Move Files Between Document Libraries with Metadata and Version History

Requirement: Move Files Between Document Libraries with Metadata and Version History
We have a very large document library with more than 100,000 documents which is causing search crawl and latency issues. So, decided to archive old documents into separate document libraries year-wise.
Stop: Before proceeding with any of the below method, Save your source list or library as a template without including content and create new list from the list template, So that your source and destination libraries will look a like!

Solution 1 - Using Content and Structure page to move files with versions and Metadata:
All SharePoint versions including MOSS 2007, SharePoint 2010 and SharePoint 2013 supports this functionality.
  • Go to Site settings >> Click on "Content and structure" link under Site Administration section
    sharepoint move files with version history
  • Pick the items/files to be moved, Click on Actions >> Move 
  • Select the target list or library and click "OK" to complete move operation.
This sends files with version history and metadata to the target list.

Solution 2: Move files between document libraries programmatically using PowerShell:
Lets use PowerShell script to move files between lists: The idea is to create sub-folder for each Month and move documents into sub-folders based on their creation date.
#For MOSS 2007 compatibility
[void][System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint")

Function global:Get-SPWeb($url)
{
  $site= New-Object Microsoft.SharePoint.SPSite($url)
        if($site -ne $null)
            {
               $web=$site.OpenWeb();        
            }
    return $web
}

#Get the web and List
$Web = Get-SPWeb "http://intranet.sharepoint.com/sites/Marketing/"
$SourceList = $web.Lists["Proposals"]
$TargetList = $Web.Lists["Proposal Archive 2009"]

#Get all Files Created in 2009
 $Query = '<Where><And><Geq><FieldRef Name="Created" /><Value IncludeTimeValue="TRUE" Type="DateTime">2009-01-01T00:00:00Z</Value></Geq><Leq><FieldRef Name="Created" /><Value IncludeTimeValue="TRUE" Type="DateTime">2009-12-31T23:59:59Z</Value></Leq></And></Where>'
 $SPQuery = new-object Microsoft.SharePoint.SPQuery
 #$SPQuery.ViewAttributes = "Scope='Recursive'" #To include Sub-folders in the library
 $SPQuery.Query = $Query
 $SourceFilesCollection =$SourceList.GetItems($SPQuery)

Write-host "Total number of files found: "$SourceFilesCollection.count

#Move each file to the destination folder
foreach($item in $SourceFilesCollection)
{
  #Get the Source File
  $file = $Web.GetFile($item.File.URL)

  #Get the Month value from the File crated date
  $MonthValue = $item.File.TimeCreated.ToString('MMMM')
  
  # Try to Get the Sub-Folder in the Library!
  $TargetFolder = $TargetList.ParentWeb.GetFolder($TargetList.RootFolder.Url + "/" +$MonthValue);
  
  #If the folder doesn't exists, Create!
  if ($TargetFolder.Exists -eq $false)
   {
     $TargetFolder = $TargetList.Folders.Add("", [Microsoft.SharePoint.SPFileSystemObjectType]::Folder, $MonthValue)
     $TargetFolder.Update() 
   }

   #Move the File
   $file.MoveTo($TargetFolder.Url + "/" + $File.name)
  
}
While the Move operation preserves Metadata and version history, Copy doesn't!

Solution 3: Move files using SharePoint designer
  • Open your site in SharePoint Designer
  • Go to All Files >> Navigate to source library. Select files you want to copy/move, choose cut/copy
    move files using sharepoint designer
  • Go to your target library, Right click and choose "Paste"
Tips: SharePoint general rule of thumb for better performance on large list and libraries: Have < 2000 files per container (list/library/folder).
All of the above methods move documents between libraries of the same site collection! To copy files between document libraries using PowerShell, use: Copy Files Between Document Libraries in SharePoint using PowerShell
Move Files Between Document Libraries with Metadata and Version History Move Files Between Document Libraries with Metadata and Version History Reviewed by Salaudeen Rajack on 3:16 PM Rating: 5

4 comments:

  1. Thanks a lot, this is really a time saver

    ReplyDelete
  2. How about moving libraries between site collections?

    ReplyDelete
  3. What I need to do is move folders and their contents from one library to another within the same site collection, maintaining as much metadata as possible. Will this do that?

    ReplyDelete

Please Login and comment to get your questions answered!

Powered by Blogger.