如果您不使用内容类型,那么您需要在新库上重新创建源库的字段。这使用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()
请注意,您还需要在需要时从源库视图添加到目标库。
上述脚本不会复制附加到库的任何表单或工作流。