Sunday, June 3, 2012

how to upload a file using client object model in sharepoint 2010

Here i will show how to upload a file using client object model in share point 2010.The location of the file has been assigned to a variable "filepath" .
string filepath=@"d:\projects\testshareupload\orderdata.doc";
ClientContext clc = new ClientContext(siteurl);
Web w = clc.Web;
FileCreationInformation Fi = new FileCreationInformation();
Fi.Content = System.IO.File.ReadAllBytes(filepath);
Fi.Url = "orderdata.doc";
List datafiles = web.Lists.GetByTitle("Files");
SP.File uFile = docs.RootFolder.Files.Add(Fileinfo);
clc.Load(uFile);
clc.ExecuteQuery();
 
After all we may get any error regarding file size,we have increase the maximum upload file size by using the below code
SPWebService sws = SPWebService.ContentService;
SPClientRequestServiceSettings SpCclientSettings = sws.ClientRequestServiceSettings; 
SpCclientSettings.MaxReceivedMessageSize = 5242880; 
sws.Update(); 
 

1 comment:

Teetho said...

Here is site http://bit.ly/KXrI9u from where you can easily learn about that.

Bel