Showing posts with label Document Library. Show all posts
Tuesday, May 26, 2015
Easily Upload Document to Doc Library using Client Object Model in SharePoint 2013,SharePoint 2010
Posted by
Santhosh,
on
5:57 AM
Hi friends,
Thanks for visiting my blog .
In this post i would like to post about how to upload a document to Document Library using
Client Object Model
Please find below method to upload the document to Doc Library in SharePoint .
- public Boolean UploadDocument(String fileName, String filePath, List metaDataList)
- {
- SP.ClientContext ctx = new SP.ClientContext(“http: //yoursharepointURL”);
- Web web = ctx.Web;
- FileCreationInformation newFile = new FileCreationInformation();
- newFile.Content = System.IO.File.ReadAllBytes(@”C: \TestFile.doc”);
- newFile.Url = “ / ” + fileName;
- List docs = web.Lists.GetByTitle(“Shared Documents”);
- Microsoft.SharePoint.Client.File uploadFile = docs.RootFolder.Files.Add(newFile);
- context.Load(uploadFile);
- context.ExecuteQuery();
- SPClient.ListItem item = uploadFile.ListItemAllFields;
- //Set the metadata
- string docTitle = string.Empty;
- item[“Title”] = docTitle;
- item.Update();
- context.ExecuteQuery();
- }
Thanks
Subscribe to:
Posts
(
Atom
)