如果您不使用內容類型,那麼您需要在新庫上重新創建源庫的字段。這使用SPFieldCollection的AddFieldAsXml
方法,如下面的例子是在PowerShell中非常簡單:
if ((Get-PSSnapin "Microsoft.SharePoint.PowerShell" -ErrorAction SilentlyContinue) -eq $null) {
Add-PSSnapin "Microsoft.SharePoint.PowerShell"
}
$web = get-spweb "http://bp1amsapt229:14146/gom/mdrcs"
$source = $web.lists["General"]
$newListId = $web.lists.add("W_General", $source.Description, $source.BaseTemplate)
$web.Update()
$list = $web.lists.GetList($newListId,$true)
$source.fields | ForEach-Object{
if(-not $_.FromBaseType){
write-host "adding $($_.Title)... " -NoNewline -ForegroundColor Yellow
$dest.Fields.AddFieldAsXml($_.SchemaXml);
$dest.Update();
}else{
write-host "skipped adding $($_.Title)" -ForegroundColor Gray
}
}
$source.Views | ForEach-Object{
write-host "adding view '$($_.Title)'... "
$dest.Views.Add($_.Title, $_.ViewFields, $_.Query, $_.RowLimit, $_.Paged, $_.DefaultView)
$dest.Update()
}
$web.Dispose()
請注意,您還需要在需要時從源庫視圖添加到目標庫。
上述腳本不會複製附加到庫的任何表單或工作流。