TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
C# Corner
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Programmatically Upload Document using Client Object Model in SharePoint
Rajkiran Swain
May 26
2015
Code
24.1
k
0
0
facebook
twitter
linkedIn
Reddit
WhatsApp
Email
Bookmark
expand
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