2013-06-28 4 views
0

저는 셰어 포인트 온라인 서버의 한 목록에서 다른 목록으로 항목을 복사하는 스크립트를 작성하고 있습니다. 나는 2013 쉘 포인트 Client Side Object Model (CSOM)을 사용하여 PowerShell ISE에서 이것을 스크립팅하고 있습니다. 이것은 쉬운 일이되어야하지만 그것은 정반대의 것을 증명하고 있습니다. 지금까지 필자는 camlquery를 사용하여 모든 항목을 검색 할 수 있었지만 그 항목과 첨부 파일을 다른 목록에 복사하려고했습니다.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() 
} 

오류 메시지가 말한다 : "리스트 아카이브가 실패 I 나타나는 오류는 모든 항목에서 모든 첨부 파일을 검색하는 attachmentCollection을 설정하려고 시도에서이다, 여기에 문제를 나타내는 스크립트의 일부입니다 at :이 오류 메시지와 함께 : 생성자를 찾을 수 없습니다. Microsoft.SharePoint.Client.AttachmentCollection 유형의 적절한 생성자를 찾을 수 없습니다. "

첨부 파일로 새 개체를 만들려고해도 동일한 오류가 발생하며 생성자를 찾을 수 없습니다. 이것은 생성자가 client.dll에 있어야하지만 운이 없으므로 이상합니다. 심지어 2013 CSOM 파일을 복구하려고 시도했지만 오류가 발견되지 않았습니다. 어떤 도움이라도 고맙습니다. 감사합니다.

답변

0

많은 양의 시행 착오 끝에 attachmentCollection 객체를 처리 할 때 새 객체를 선언 할 필요가 없다는 것을 발견했습니다. 변수를 다음과 같이 간단히 설정할 수 있습니다.

$attachments = $item.AttachmentFiles 

$ attachments는 이제 첨부 파일의 배열입니다.

그러나 공유 지점에는 이러한 첨부 파일을 관리하기위한 끔찍한 시스템이 있으며 처음에는 폴더를 저장할 폴더가 없으며 직접 폴더를 만들 수도 있으므로 큰 문제는 새 항목에 복사/추가하는 것입니다. 항목 간 첨부 파일을 복사하는 데 여전히 문제가 있습니다. 누군가이 작업을 수행하는 방법에 대한 지식이있는 경우 해당 항목도 도움이됩니다.

AttachmentFiles 속성에 첨부 파일을 추가 할 때의 주된 문제점은 $ item.AttachmentFiles.Add() 메서드를 사용한다는 것입니다.이 메서드는 매개 변수가 첨부 파일이 아닌 AttachmentCreationInformation 개체 여야합니다. 나는 새로운 아이템에 이미 존재하는 첨부 파일을 추가 할 수 있도록이 함수를 어떻게 만들 것인지 잘 모른다.

관련 문제