我有一个Windows应用程序,可以将.pdfs保存到SharePoint文档库。除了这个文件,它工作正常。每当我在这个10.1MB文件中使用SaveBinaryDirect时,我都会遇到以下异常:
System.Net.WebException: The underlying connection was closed: An unexpected error occurred on a receive. ---> System.IO.IOException: Unable to read data from the transport connection: An established connection was aborted by the software in your host machine. ---> System.Net.Sockets.SocketException: An established connection was aborted by the software in your host machine
at System.Net.Sockets.Socket.Receive(Byte[] buffer, Int32 offset, Int32 size, SocketFlags socketFlags)
at System.Net.Sockets.NetworkStream.Read(Byte[] buffer, Int32 offset, Int32 size)
--- End of inner exception stack trace ---
at System.Net.Sockets.NetworkStream.Read(Byte[] buffer, Int32 offset, Int32 size)
at System.Net.PooledStream.Read(Byte[] buffer, Int32 offset, Int32 size)
at System.Net.Connection.SyncRead(HttpWebRequest request, Boolean userRetrievedStream, Boolean probeRead)
--- End of inner exception stack trace ---
at System.Net.HttpWebRequest.GetResponse()
at Microsoft.SharePoint.Client.SPWebRequestExecutor.Execute()
at Microsoft.SharePoint.Client.File.SaveBinary(ClientContext context, String serverRelativeUrl, Stream stream, String etag, Boolean overwriteIfExists, SaveBinaryCheckMode checkMode)
at Microsoft.SharePoint.Client.File.SaveBinaryDirect(ClientContext context, String serverRelativeUrl, Stream stream, Boolean overwriteIfExists)
at BKWatch.BKWatchViewModel.UploadDocument(String siteURL, String documentListName, String documentListURL, String documentName, Byte[] documentStream, Int64 AccountId, String DebtorName, Nullable`1 Pages, String Title)
我已经尝试了以下内容:
clientContext.PendingRequest.RequestExecutor.WebRequest.KeepAlive = false;
System.Net.ServicePointManager.MaxServicePointIdleTime = 600000;
clientContext.RequestTimeout = 600000;
增加SharePoint中的最大大小 - 已经达到50 MB 增加IIS web.config中的最大大小 - 已经是2GB
感谢。
答案 0 :(得分:0)
经过与Microsoft的几次长时间电话交谈之后,他们认为SaveBinaryDirect代码中存在一个错误,并建议我使用ClientObject.Add功能。似乎到目前为止工作。
答案 1 :(得分:0)
我在连续上传大量文件时遇到了Microsoft.SharePoint.Client.File.SaveBinaryDirect的这个问题。
对此的修复是在每次使用SaveBinaryDirect时,使用try-catch包装它,并捕获System.Net.WebException。
捕获Webexception后,运行您之前运行的相同SaveBinaryDirect命令,它应该可以正常工作。