我正在尝试将现有网站列添加到SharePoint列表中。我尝试了以下代码:
#Setup the context
$listTitle = "VersionCleanup2247"
$clientContext = New-Object Microsoft.SharePoint.Client.ClientContext($siteURL)
$clientContext.Load($clientContext.Web);
$clientContext.Load($clientContext.Web.Lists);
$clientContext.ExecuteQuery()
$list = $clientContext.Web.lists | where{$_.Title -eq $listTitle}
if($list)
{
Write-Host "list is already there. Loading the existing list."
$list = $clientContext.Web.lists.GetByTitle($listTitle)
$clientContext.Load($list);
$clientContext.ExecuteQuery()
Write-Host "Loaded" -ForegroundColor Green
}
Write-Host "Loading the default view of list"
$defaultView = $list.defaultView
$clientContext.Load($defaultView)
$clientContext.ExecuteQuery()
Write-Host "Loaded" -ForegroundColor Green
Write-Host "Loading the available field in the current site"
$siteColumns = $clientContext.Web.Fields
$clientContext.Load($siteColumns)
$clientContext.ExecuteQuery()
Write-Host "Loaded" -ForegroundColor Green
Write-host "adding comments fields from available site columns to the list"
$colName = $siteColumns | Where {$_.InternalName -eq "_Comments"}
$clientContext.Load($colName)
$clientContext.ExecuteQuery()
$list.Fields.Add($colName)
$list.Update()
$clientContext.ExecuteQuery()
$defaultView.ViewFields.Add("Comments")
$defaultView.Update()
$clientContext.ExecuteQuery()
在这里,我试图添加一列,其内部名称为_Comments
,显示名称为Comments
。但是在添加它时,出现以下错误:
错误信息!带有“ 0”参数的调用“ ExecuteQuery”的异常:“字段或属性“ DescriptionResource”不存在。”
正在加载的dll文件如下:
Add-Type -Path "c:\Microsoft.SharePoint.Client.dll"
Add-Type -Path "c:\Microsoft.SharePoint.Client.Runtime.dll"
我在网站上拥有完整的管理员访问权限。任何建议,将不胜感激。谢谢!