我有一个将pdf文件保存到SharePoint文档库的Windows应用程序。除了这个文件,它工作得很好。每当我对这个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的最大大小-已经是50mb增加IIS web的最大大小。配置-已经是2GB
谢谢。
在与微软进行了几次长时间的电话交谈后,他们认为SaveBinaryDirect代码中存在错误,并建议我使用ClientObject。而是添加功能。
我在使用Microsoft.SharePoint.Client.File.SaveBinaryDirect上传多个大文件时遇到了这个问题。
解决这个问题的方法是,每次使用SaveBinaryDirect时,用try-catch包装它,并捕获system.net.webeexception。
一旦webeexception被捕获,运行相同的SaveBinaryDirect命令你之前运行,它应该工作。