Skip to main content

Posts

Showing posts from September 19, 2011

SharePoint 2010: Attach files to List/Library using Managed Client Object Model

Client Objet Model (OM) is a great new addition in SharePoint 2010. I have discussed before how to manipulate lists and list items using Managed Object Model. Today I’ll discuss on how to attach file to list item or add file to library using Managed Client Object Model. Upload File in Library The following code snippet shows how to upload file in document library: public void UploadFileInLibrary( string siteUrl, string webName, string libraryName, string subfolderPath, string fileName) { using (ClientContext clientContext = new ClientContext(siteUrl)) { string uploadLocation = Path.GetFileName(fileName); if (! string .IsNullOrEmpty(subfolderPath)) { uploadLocation = string .Format( "{0}/{1}" , subfolderPath, uploadLocation); } uploadLocation = string .Format( "/{0}/{1}/{2}" , webName, libraryName, uploadLocation); var list = clientContext.Web.Lists.GetByTitle(libraryName);