I want to upload large files to SharePoint 2010 from web service using client object model.
Below is the code, which i am using to upload file to sharepoint.
using (MemoryStream stream = new MemoryStream(System.IO.File.ReadAllBytes(file)))
{
Microsoft.SharePoint.Client.File.SaveBinaryDirect(ctx, relativeurl, stream, true);
}
Problem is, it is working fine for small files only. but when i am uploading file with 120 MB, then it is throwing Operation TimeOut error. Then i set time out to 20 minutes using
spcontext.RequestTimeout = 1200000;
But still it is not working. Then i found that i need to increase file upload size limit on web application level.
So i set it to 200 MB, which is shown below:

But still it didn't work.
Then i found below site reference http://thuansoldier.net/?p=4328, which says that we need to allow messages larger than 2097152 bytes.
So i ran below commands on my SharePoint server also
$a = [Microsoft.SharePoint.Administration.SPWebService]::ContentService
$a.ClientRequestServiceSettings.MaxReceivedMessageSize = 200000000
$a.Update()
But no luck.
Can anyone please help me on this?
Below is the my webservice code:
[WebMethod]
public string UploadFilesToSharePoint()
{
try
{
string file = @"C:\TEST\Professional_Microsoft_SQL_Server_2012_Analysis_Services_with_MDX.pdf";
UploadDocumentRPC("http://domain:port/sites/test/", "Docs", file);
return "Successfully Uploaded.";
}
catch (Exception ex)
{
throw new Exception(ex.Message.ToString());
}
}
public static void UploadDocumentRPC(string siteUrl, string libraryName, string filePath)
{
string method = HttpUtility.UrlEncode("put document:14.0.2.5420");
string serviceName = HttpUtility.UrlEncode(siteUrl);
string document = HttpUtility.UrlEncode(libraryName + "/" + System.IO.Path.GetFileName(filePath));
string metaInfo = string.Empty;
string putOption = "overwrite";
string keepCheckedOutOption = "false";
string putComment = string.Empty;
string result = string.Empty;
string fpRPCCallStr = "method={0}&service_name={1}&document=[document_name={2};meta_info=[{3}]]&put_option={4}&comment={5}&keep_checked_out={6}";
fpRPCCallStr = String.Format(fpRPCCallStr, method, serviceName, document, metaInfo, putOption, putComment, keepCheckedOutOption);
byte[] fpRPCCall = System.Text.Encoding.UTF8.GetBytes(fpRPCCallStr + "\n");
byte[] postData = System.IO.File.ReadAllBytes(filePath);
byte[] data;
if (postData != null && postData.Length > 0)
{
data = new byte[fpRPCCall.Length + postData.Length];
fpRPCCall.CopyTo(data, 0);
postData.CopyTo(data, fpRPCCall.Length);
}
else
{
data = new byte[fpRPCCall.Length];
fpRPCCall.CopyTo(data, 0);
}
HttpWebRequest wReq = WebRequest.Create(siteUrl + "/_vti_bin/_vti_aut/author.dll") as HttpWebRequest;
NetworkCredential credentials = new NetworkCredential(Username, Password, Domain);
wReq.Credentials = credentials;
wReq.Method = "POST";
wReq.Timeout = 1000000;
wReq.ContentType = "application/x-vermeer-urlencoded";
wReq.Headers.Add("X-Vermeer-Content-Type", "application/x-vermeer-urlencoded");
wReq.ContentLength = data.Length;
using (System.IO.Stream requestStream = wReq.GetRequestStream())
{
int chunkSize = 2097152;
int tailSize;
int chunkNum = Math.DivRem(data.Length, chunkSize, out tailSize);
for (int i = 0; i < chunkNum; i++)
{
requestStream.Write(data, chunkSize * i, chunkSize);
}
if (tailSize > 0)
requestStream.Write(data, chunkSize * chunkNum, tailSize);
}
WebResponse wresp = wReq.GetResponse();
using (System.IO.StreamReader sr = new System.IO.StreamReader(wresp.GetResponseStream()))
{
result = sr.ReadToEnd();
}
}
SharePointOnlineCredentials.