Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/sharepoint/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/entity-framework/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Powershell中的Sharepoint CSOM OpenBinaryDirect,未找到方法_Sharepoint_Powershell_Csom - Fatal编程技术网

Powershell中的Sharepoint CSOM OpenBinaryDirect,未找到方法

Powershell中的Sharepoint CSOM OpenBinaryDirect,未找到方法,sharepoint,powershell,csom,Sharepoint,Powershell,Csom,我正在尝试使用powershell和Sharepoint 2013 CSOM将一个项目的附件复制到另一个列表中的新项目。我已经能够成功地为新项目生成附件文件夹,因此理论上我所需要做的就是将文件从旧的附件文件夹移动到新的附件文件夹。CopyTo和MoveTo似乎只适用于移动列表中的文件,所以我想在站点上下文中使用OpenBinaryDirect和SaveBinaryDirect。但是,在powershell中,调用这些方法之一会导致以下错误:方法调用失败,因为[System.RuntimeType

我正在尝试使用powershell和Sharepoint 2013 CSOM将一个项目的附件复制到另一个列表中的新项目。我已经能够成功地为新项目生成附件文件夹,因此理论上我所需要做的就是将文件从旧的附件文件夹移动到新的附件文件夹。CopyTo和MoveTo似乎只适用于移动列表中的文件,所以我想在站点上下文中使用OpenBinaryDirect和SaveBinaryDirect。但是,在powershell中,调用这些方法之一会导致以下错误:方法调用失败,因为[System.RuntimeType]不包含名为“OpenBinaryDirect”的方法

$attachments = $item.AttachmentFiles
if($attachments.Count -gt 0)
{
    #Creates a temporary attachment for the new item to genereate a folder, will be deleted later.
    $attCI = New-Object Microsoft.SharePoint.Client.AttachmentCreationInformation
    $attCI.FileName = "TempAttach"
    $enc = New-Object System.Text.ASCIIEncoding
    $buffer = [byte[]] $enc.GetBytes("Temp attachment contents")
    $memStream = New-Object System.IO.MemoryStream (,$buffer)
    $attCI.contentStream = $memStream
    $newItem.AttachmentFiles.Add($attCI)

    $ctx.load($newItem)
    $sourceIN = $sourceList.Title
    $archIN = $archList.Title
    $sourcePath = "/" + "Lists/$sourceIN/Attachments/" + $item.Id
    $archPath = "/" + "Lists/$archIN/Attachments/" + $newItem.Id
    $sFolder = $web.GetFolderByServerRelativeUrl($sourcePath)
    $aFolder = $web.GetFolderByServerRelativeURL($archPath)
    $ctx.load($sFolder)
    $ctx.load($aFolder)
    $ctx.ExecuteQuery()
    $sFiles = $sFolder.Files
    $aFiles = $aFolder.Files
    $ctx.load($sFiles)
    $ctx.load($aFiles)
    $ctx.ExecuteQuery()
    foreach($file in $sFiles)
    {
        $fileInfo = [Microsoft.SharePoint.Client.File].OpenBinaryDirect($ctx, $file.ServerRelativeUrl)
        [Microsoft.Sharepoint.Client.File].SaveBinaryDirect($ctx, $archPath, $fileInfo.Stream, $true)
    }
}
$ctx.ExecuteQuery()

如果您能帮助BinaryDirect方法发挥作用,或者只是使用powershell+CSOM跨列表复制附件的一般策略,我们将不胜感激。

您调用静态方法的语法错误。您需要
[Microsoft.SharePoint.Client.File]::OpenBinaryDirect(…)


注意类型名和方法名之间的双冒号语法
。同样,对于<代码> SaveBinaryDirect <代码>调用.< /P>请考虑将LaTKIN的答案标记为答案。