C# Corner
Tech
News
Videos
Forums
Trainings
Books
Events
More
Interviews
Jobs
Live
Learn
Career
Members
Blogs
Challenges
Certifications
Bounties
Contribute
Article
Blog
Video
Ebook
Interview Question
Collapse
Feed
Dashboard
Wallet
Learn
Achievements
Network
Refer
Rewards
SharpGPT
Premium
Contribute
Article
Blog
Video
Ebook
Interview Question
Register
Login
Programmatically Upload Document using Client Object Model in SharePoint
WhatsApp
Rajkiran Swain
May 26
2015
25
k
0
0
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();
}
SharePoint
Client object model
Programmatical Upload document using Client object model
Up Next
Programmatically Upload Document using Client Object Model in SharePoint