Programmatically upload documents using SharePoint 2010 Client Object Model

Home | SharePoint Development | Programmatically upload documents using SharePoint 2010 Client Object Model

The following code snippet helps us to programmatically upload documents to document library, using Client Object Model.

 using (ClientContext clientContext = new ClientContext("http://yoursitecollection"))
            {

                Web oWeb = clientContext.Web;
                List oList = oWeb.Lists.GetByTitle("Shared Documents");               

                FileCreationInformation oFileCreationInformation = new FileCreationInformation();                  
                
                byte[] filecontent=System.IO.File.ReadAllBytes(@"C:SundarTestFile.txt");
                oFileCreationInformation.Content = filecontent;
                oFileCreationInformation.Url = @"http://yoursitecollection/Shared Documents/TestFile.txt";              


                oList.RootFolder.Files.Add(oFileCreationInformation);
                

                clientContext.Load(oList);
                clientContext.ExecuteQuery();        
                
                
            }

 Subscribe to my blog

One thought on “Programmatically upload documents using SharePoint 2010 Client Object Model

Leave a Reply