Sharepoint UploadFile'指定的参数超出了有效值的范围'

时间:2017-11-27 12:17:03

标签: c# sharepoint csom

我正在尝试在远程事件接收器中将文件从一个库复制到另一个库。

到达UploadFile - 函数时,出现以下错误:

Specified argument was out of the range of valid values. Parameter name: bytesToCopy

可以找到有关该功能的信息here。它有以下签名:

public static Microsoft.SharePoint.Client.File UploadFile (this Microsoft.SharePoint.Client.Folder folder, string fileName, System.IO.Stream stream, bool overwriteIfExists);

我的代码是:

using (System.IO.MemoryStream stream = new System.IO.MemoryStream())
{
    ClientResult<Stream> data = curItem.File.OpenBinaryStream();
    clientContext.ExecuteQuery();

    if (data != null && data.Value != null)
    {

         data.Value.CopyTo(stream);
         UploadedFile = destinationList.RootFolder.UploadFile(curItem.File.Name.ToString(), stream, true);
    }
}

注意:curItemdestinationListcurItem.File都已加载到上下文中。

编辑,完成错误:

   at Microsoft.SharePoint.Client.ClientRequest.ProcessResponseStream(Stream responseStream)
   at Microsoft.SharePoint.Client.ClientRequest.ProcessResponse()
   at Microsoft.SharePoint.Client.ClientContextExtensions.ExecuteQueryImplementation(ClientRuntimeContext clientContext, Int32 retryCount, Int32 delay, String userAgent)
   at Microsoft.SharePoint.Client.FileFolderExtensions.UploadFile(Folder folder, String fileName, Stream stream, Boolean overwriteIfExists)
   at PG.SHP.SCE.QCSPAddInWeb.Services.AppEventReceiver.HandleItemCheckedIn(SPRemoteEventProperties properties) in C:\Users\OBJ_JDWR\Source\Workspaces\SharePoint\SCE\Main\Source\PG.SHP.SCE\Source\PG.SHP.SCE.QCSPAddInWeb\Services\AppEventReceiver.svc.cs:line 288

第288行: enter image description here

如何摆脱错误?

1 个答案:

答案 0 :(得分:3)

快速谷歌搜索引导我this article

有人遇到过类似的问题(虽然他认为这与文件大小有关)并通过在将流发送到SharePoint之前重置流来解决它:

composer diagnose -vvv

希望这对你有用:)