This is an example of how to upload a file with the C# Client Side Object Model (CSOM):
internal static File UploadFile(ClientContext clientContext, Web web, string filePath, Folder folder, string fileName, string title)
{
string target = folder.ServerRelativeUrl + "/" + fileName;
FileCreationInformation fci = new FileCreationInformation();
fci.Overwrite = true;
fci.Url = target;
fci.Content = System.IO.File.ReadAllBytes(filePath);
File uploadedFile = folder.Files.Add(fci);
uploadedFile.ListItemAllFields["Title"] = title;
uploadedFile.ListItemAllFields.Update();
clientContext.ExecuteQuery();
if (uploadedFile.CheckOutType != CheckOutType.None)
{
uploadedFile.CheckIn("Initial Upload", CheckinType.MajorCheckIn);
}
clientContext.Load(uploadedFile);
clientContext.ExecuteQuery();
return uploadedFile;
}
Note that this method also lets you set a title for the document, as well as the file name, and it checks the document in for you if required.


