我正在编写一个脚本,将项目从一个列表复制到另一个SharePoint Server上。我正在使用2013 SharePointPort客户端对象模型(CSOM)在PowerShell ISE中编写脚本。这应该是一件容易的事,但事实证明恰恰相反。到目前为止,我可以使用camlquery来检索所有项目,我只是试图将这些项目及其附件复制到另一个列表中。我收到的错误是试图建立一个attachmentCollection检索所有来自任何项目的附件,这里是代表问题的脚本的一部分:Sharepoint Online 2013 AttachmentCollection对象的CSOM构造函数错误?
Add-Type -Path "C:\Program Files\Common Files\microsoft shared\Web Server Extensions\15\ISAPI\Microsoft.SharePoint.Client.dll"
Add-Type -Path "C:\Program Files\Common Files\microsoft shared\Web Server Extensions\15\ISAPI\Microsoft.SharePoint.Client.Runtime.dll"
$siteURL = "https://mysite.sharepoint.com"
$password = Read-Host -Prompt "Enter Password" -AsSecureString
$ctx = New-Object Microsoft.Sharepoint.Client.ClientContext($siteURL)
$credentials = New-Object Microsoft.Sharepoint.Client.SharepointOnlineCredentials("[email protected]", $password)
$ctx.Credentials = $credentials
#...Bunch of code that establishes/loads web/lists/items, all works fine
function CopyItem $itemToCopy
function CopyItem ($oldItem)
{
Write-Host "Copying item" $oldItem.ID
$newItemCI = New-Object Microsoft.SharePoint.Client.ListItemCreationInformation
$newItem = $archList.AddItem($newItemCI)
$ctx.load($newItem)
#Update fields
$ctx.load($sourceList.Fields)
$ctx.ExecuteQuery()
foreach($field in $sourceList.Fields)
{
$newItem[$field.InternalName] = $oldItem[$field.InternalName]
}
$attachments = New-Object Microsoft.SharePoint.Client.AttachmentCollection #ERROR HERE
$attachments = $oldItem.AttachmentFiles
$ctx.load($attachments)
$newItem.AttachmentFiles.Add($attachments)
$newItem.Update()
$ctx.load($newItem)
$ctx.ExecuteQuery()
}
错误消息说:“列表存档失败at:with this error message:Constructor not found。Can not find a suitable constructor for type Microsoft.SharePoint.Client.AttachmentCollection。“
如果我尝试创建新的对象作为附件,我也会得到相同的错误,找不到构造函数。这很奇怪,因为构造函数应该在client.dll中,但没有运气。我甚至尝试修复我的2013 CSOM文件,没有发现错误。任何帮助表示赞赏,谢谢。