4
votes

I am trying to upload files greater than 100 MB size to SharePoint Portal for Office 365. I have tried three different ways to achieve the same.

  1. Copy Web Service, along with the httpRuntime Setting in place with maxRequestLength set as 2097151 and executionTimeout as 14400. Also, I did try setting the Timeout as "Infinite" and "60000".
    Error: The underlying connection was closed: An unexpected error occurred on a send.

  2. Web Client, using UploadDataAsync method to "PUT" the file bytes to the destination Url. Even with this, the httpRuntime setting was in place as above.
    Error: Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host.

  3. HttpWebRequest, with ServicePointManager.Expect100Continue set to false. Also tried the same with SendChunked as both true and false.
    Error: The request was aborted: The request was canceled.

Apart from all these, I have also added

protected override System.Net.WebRequest GetWebRequest(Uri uri)
{
 System.Net.HttpWebRequest webRequest = 
  (System.Net.HttpWebRequest) base.GetWebRequest(uri);
 webRequest.KeepAlive = false;
 return webRequest;
}

in the proxy class generated for Copy service. The limitation is I can't use CSOM to upload the files.

And still the Upload request times out every time. Any help would be very much appreciated.

Thanks in advance.

2
as far as I know this might be some setting with IIS though you might need to check this out with Microsoftlem.mallari

2 Answers

1
votes

Try using the following piece of code :-

           WebRequest webRequest = WebRequest.Create(url);
           HttpWebRequest request = (HttpWebRequest)webRequest;
           request.CookieContainer = CookieContainer;
           request.Method = "PUT";
           request.KeepAlive = true;
           request.Timeout = Timeout.Infinite;
           byte[] buffer = new byte[1024];
           using (Stream stream = request.GetRequestStream())
           {
               using (MemoryStream memoryStream = new MemoryStream(fileBytes))
               {
                   memoryStream.Seek(0, SeekOrigin.Begin);
                   for (int i = memoryStream.Read(buffer, 0, buffer.Length); i > 0;
                       i = memoryStream.Read(buffer, 0, buffer.Length))
                   {
                       stream.Write(buffer, 0, i);
                   }
               }
           }
           WebResponse response = request.GetResponse();
           response.Close();
0
votes

Have you tried to change the default maximum upload file size? What version of SharePoint are you using?