【问题标题】:Sharepoint CSOM OpenBinaryDirect in Powershell, Method not foundPowershell 中的 Sharepoint CSOM OpenBinaryDirect,找不到方法
【发布时间】:2013-06-30 04:52:45
【问题描述】:

我正在尝试使用 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 跨列表复制附件的通用策略的帮助将不胜感激。

【问题讨论】:

  • 请考虑将 latkin 的答案标记为答案

标签: sharepoint powershell csom


【解决方案1】:

调用静态方法的语法有误。你要[Microsoft.SharePoint.Client.File]::OpenBinaryDirect( ... )

注意类型名称和方法名称之间的双冒号语法::SaveBinaryDirect 调用也一样。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2023-03-19
    • 2017-12-01
    • 1970-01-01
    • 1970-01-01
    • 2017-12-31
    • 2017-04-04
    • 2014-03-13
    • 2023-03-09
    相关资源
    最近更新 更多