Click here to Skip to main content
15,937,779 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Cant upload the file more than 3 MB to SharePoint Library using Client Object model.

Following is the two ways i tried.

Way 1:
C#
using (FileStream fs = new FileStream(strCurrentTempPath, FileMode.Open))
{                    SP.File.SaveBinaryDirect(ClientContextName,ServerRelativeUrl, FileStream, true);
}


Way 2:
Microsoft.SharePoint.Client.File file = oWeb.GetFileByServerRelativeUrl(ServerRelativeUrl);

FileVersionCollection versions = file.Versions;

FileSaveBinaryInformation fsbi = new FileSaveBinaryInformation();

ClientContext ctx = new ClientContext(RootUrl);
byte[] binaryData =System.IO.File.ReadAllBytes(strCurrentTempPath);

fsbi.Content = binaryData;
file.SaveBinary(fsbi);

clientContext.Load(file);
clientContext.Load(versions);
clientContext.ExecuteQuery();

Exception:
400 Bad Request
Posted
v2

1 solution

In you web.config, increase the maxRequestLength.
XML
<system.web>
   <httpruntime maxrequestlength="1000000" executiontimeout="240" requestvalidationmode="2.0" />
   </system.web>
 
Share this answer
 
Comments
sugumaran srinuvasan 8-Nov-12 9:33am    
i tried,this one not workout in my case.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900