Showing posts with label SharePoint File Read and Write using CSOM. Show all posts
Showing posts with label SharePoint File Read and Write using CSOM. Show all posts

Monday, 30 June 2014

SharePoint File Read and Write using CSOM

using (System.IO.FileStream objFileS = new System.IO.FileStream(@"D:\myexcel.xlsx", System.IO.FileMode.Open))
{
SP.FileCreationInformation objFileC = new SP.FileCreationInformation();
objFileC.ContentStream = objFileS;
objFileC.Url = System.DateTime.Now.ToLongTimeString().Replace(':',' ') + ".xlsx";
objFileC.Overwrite = true;
SP.List objLib = clientContext.Web.Lists.GetByTitle("MyLibrary");
SP.File uploadFile = objLib.RootFolder.Files.Add(objFileC);
clientContext.Load(uploadFile);
clientContext.ExecuteQuery();
}