使用元数据和版本历史记录在文档库之间移动文件
要求:在具有元数据和版本历史记录的文档库之间移动文件。
我们拥有庞大的文档库,包含超过 100,000 个文档,导致搜索爬行和延迟问题。因此,我决定每年将旧文档归档到单独的文档库中。
停止:在继续执行以下任何方法之前,将源列表或库另存为模板而不包含内容,并从列表模板创建新列表,以便您的源库和目标库看起来相似!
解决方案 1 - 使用内容和结构页面移动带有版本和元数据的文件:
所有 SharePoint 版本(包括 MOSS 2007、SharePoint 2010 和 SharePoint 2013)都支持此功能。
这会将带有版本历史记录和元数据的文件发送到目标列表。
解决方案 2:使用 PowerShell 以编程方式在文档库之间移动文件
让我们使用 PowerShell 脚本在列表之间移动文件:想法是为每个月创建一个子文件夹,并根据创建日期将文档移动到子文件夹中。
Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue
#Get the web and List
$Web = Get-SPWeb "https://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 created 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 exist, Create!
if ($TargetFolder.Exists -eq $false)
{
$TargetFolder = $TargetList.Folders.Add([string]::Empty, [Microsoft.SharePoint.SPFileSystemObjectType]::Folder, $MonthValue)
$TargetFolder.Update()
}
#Move the File
$file.MoveTo($TargetFolder.Url + "/" + $File.name)
}
虽然移动操作会保留元数据和版本历史记录,但复制不会!此外,“浏览视图”从源库拖放到目标位置也会保留版本。
解决方案 3:使用 SharePoint 设计器移动文件
提示:为了在大型列表和库上获得更好的性能,SharePoint 一般经验法则是:每个容器(列表/库/文件夹)的文件数少于 2000 个。
所有上述方法都可以在同一网站集的库之间移动文档!要使用 PowerShell 在文档库之间复制文件,请使用:使用 PowerShell 在 SharePoint 中的文档库之间复制文件

