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
No comments :
Post a Comment