try
{
using (var clientContext = new ClientContext(_helper.WebRoot()))
{
var web = clientContext.Web;
clientContext.Load(web, website => website.ServerRelativeUrl);
clientContext.ExecuteQuery();
var serverRelativeURL = web.ServerRelativeUrl + "/" + "Documents/" + caseNumber.Substring(0, caseNumber.IndexOf("-")) + "/" + caseNumber + "/" + fileName;
using (FileStream fs = new FileStream(Path.Combine(localPath, fileName), FileMode.OpenOrCreate))
{
Microsoft.SharePoint.Client.File.SaveBinaryDirect(clientContext, serverRelativeURL, fs, true);
}
Microsoft.SharePoint.Client.File newFile = web.GetFileByServerRelativeUrl(serverRelativeURL);
clientContext.Load(newFile);
clientContext.ExecuteQuery();
newFile.CheckOut();
newFile.ListItemAllFields["FileLeafRef"] = fileName;
newFile.ListItemAllFields["Comment1"] = comment;
newFile.ListItemAllFields["DocumentType"] = "Favourites";
newFile.ListItemAllFields["Modified_x0020_By"] = userName;
newFile.ListItemAllFields.Update();
clientContext.ExecuteQuery();
newFile.CheckIn(string.Empty, CheckinType.OverwriteCheckIn);
}
return true;
}
catch (Exception ex)
{
return false;
}