.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
 
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
david stephan

Home >> Code Snippets >> SharePoint >> Post New Resource Bookmark and Share   

 Subscribe to Code Snippets

Upload a file in sharePoint 2010 document library with the metadata

Posted By:abhays       Posted Date: August 31, 2014    Points: 40    Category: SharePoint    URL: http://www.dotnetspark.com  

Upload a file in sharePoint 2010 document library with the metadata
 

Below code explains how to upload a file  in sharePoint document library with the  metadata.

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.txt");

newFile.Url = "/" + fileName;

List docs = web.Lists.GetByTitle("MyDocs");

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();



     

Further Readings:

Responses

No response found. Be the first to respond this post

Post Comment

You must Sign In To post reply
Find More code samples in C#, ASP.Net, Vb.Net and more Here

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend