I am trying to upload files ~1GB to sharepoint 2013 on prem, I downloded Microsoft.SharePoint2013.CSOM, and tried with UploadFileSlicePerSlice but there is no such method "StartUpload" (compile error).
1 Answers
didn't I post the answer to this question here post ?
In the same article You posted there is also mentioned the method SaveBinaryDirect which should work for large files and for sure is present in the nuget You posted.
Please try something like:
class Program
{
static void Main(string[] args)
{
try
{
Console.WriteLine("start");
using (ClientContext context = new ClientContext("[SITECOLLECTION URL]"))
{
using (FileStream fs = new FileStream(@"[PATH TO FILE LIKE C:\test.png]", FileMode.Open))
{
Microsoft.SharePoint.Client.File.SaveBinaryDirect(context, "/[LIB NAME FROM URL LIKE 'DOCUMENTS']/" + "[FILE NAME LIKE 'test.png']", fs, true);
}
}
Console.WriteLine("end");
}
catch (Exception ex)
{
Console.WriteLine("error -> " + ex.Message);
}
finally
{
Console.ReadLine();
}
}
}
UPDATE
I managed just now to upload a file which had 470 MB with this method on SP2016 to which I have access almost all day. Please see:
the funny thing is that this took only 3 min to upload the file (on SP2016). This is very strange as during the day (when I have access to SP2013) I tried this method to upload 200MB file on SP2013 today morning and it took more then 1 hour for it :)... I wonder why such a difference. When I left the 0.5GB file was still during upload. I will let You know tomorrow morning did it finish and how much time did it take. I think the method generally works (and for SP2016 works ultra fast) the problem is in SP2013 where it is very slow, and stays very long in the 'hang' You mentioned.
Maybe If I have time I will have a look a the third method with the StartUpload, ContinueUpload, and FinishUpload methods on the File class, but I am not sure is it supported for SP CSOM 2013.
UPDATE 2
I finally got some results after many many tries on this upload on SP2013. What I noticed is that if we first get the byte[] array and then use this to get the filestream and use it to SaveBinaryDirect() method, than the upload is really fast and does not hang. Please for SP2013 try a very similar approach to the one I posted but like this (notice the byte array and context.HasPendingRequests condition, this is probably not needed but I had a small error and had to resolve it this way :) ):
class Program
{
static void Main(string[] args)
{
try
{
Console.WriteLine("start " + DateTime.Now.ToLongDateString() + DateTime.Now.ToLongTimeString());
using (ClientContext context = new ClientContext("[SITECOLLECTION URL]"))
{
context.RequestTimeout = -1;
Web web = context.Web;
if (context.HasPendingRequest)
context.ExecuteQuery();
byte[] fileBytes = System.IO.File.ReadAllBytes(@"[PATH TO FILE LIKE C:\test.png]");
using (var fileStream = new System.IO.MemoryStream(fileBytes))
{
Microsoft.SharePoint.Client.File.SaveBinaryDirect(context, "/[LIB NAME FROM URL LIKE 'DOCUMENTS']/" + "[FILE NAME LIKE 'test.png']", fileStream, true);
}
}
Console.WriteLine("end " + DateTime.Now.ToLongDateString() + DateTime.Now.ToLongTimeString());
}
catch (Exception ex)
{
Console.WriteLine("error -> " + ex.Message);
}
finally
{
Console.ReadLine();
}
}
}
this time I hope it will to the trick
UPDATE 3
The final code that worked (with nuget with SharePoint CSOM 2013) to upload 1GB file on SP 2013 is:
try
{
Console.WriteLine("start " + DateTime.Now.ToLongDateString() + " " + DateTime.Now.ToLongTimeString());
using (ClientContext context = new ClientContext("[URL]"))
{
context.Credentials = new NetworkCredential("[LOGIN]","[PASSWORD]","[DOMAIN]");
context.RequestTimeout = -1;
Web web = context.Web;
if (context.HasPendingRequest)
context.ExecuteQuery();
byte[] fileBytes;
using (var fs = new FileStream(@"D:\OneGB.rar", FileMode.Open, FileAccess.Read))
{
fileBytes = new byte[fs.Length];
int bytesRead = fs.Read(fileBytes, 0, fileBytes.Length);
}
using (var fileStream = new System.IO.MemoryStream(fileBytes))
{
Microsoft.SharePoint.Client.File.SaveBinaryDirect(context, "/Shared Documents/" + "OneGB.rar", fileStream, true);
}
}
Console.WriteLine("end " + DateTime.Now.ToLongDateString() + " " + DateTime.Now.ToLongTimeString());
}
catch (Exception ex)
{
Console.WriteLine("error -> " + ex.Message);
}
finally
{
Console.ReadLine();
}
Besides this I had to:
- extend the max file upload on CA for this web application,
- set on CA for this web application 'web page security Validation' on Never (in this link there is a screen how to set it)
- extend timeout on IIS
and the final result is:
sorry for the lang but I usually work in PL

- 810
- 7
- 10