I am using following code to copy a file from a document library to another. The file is copied and is there, but the fields will not be updated.
fileInfo = File.OpenBinaryDirect(srcClntCntxt, fileServerRelativeUrl);
using (ClientContext clntCntxt = ContextHelper.DestinationClientContex())
{
Web web = clntCntxt.Web;
clntCntxt.Load(web);
clntCntxt.ExecuteQuery();
string nLocation = web.ServerRelativeUrl.TrimEnd('/') + "/destLib/fileName";
File.SaveBinaryDirect(clntCntxt, nLocation, fileInfo.Stream, true);
File newFile = web.GetFileByServerRelativeUrl(nLocation);
ListItem newFileItem = newFile.ListItemAllFields;
clntCntxt.Load(newFile);
clntCntxt.Load(newFileItem);
clntCntxt.ExecuteQuery();
newFile.CheckOut();
newFileItem["MyComments"] = "test test"; //this is a multi line text
newFile.CheckIn(string.Empty, CheckinType.OverwriteCheckIn);
newFileItem.Update();
clntCntxt.ExecuteQuery();

0 commentaires:
Enregistrer un commentaire