0

I am working in SP 2013 On-premise. I am trying to re-upload documents from a folder in my local machine to my document Library. The code works fine. However, on downloading the document, I see no change in the document content even though the version gets updated (this maybe because I am also updating a field).

I am using CSOM SaveBinaryDirect method. This is my code :

FileStream stream = new FileStream(filename, FileMode.Open);
Microsoft.SharePoint.Client.File.SaveBinaryDirect(context, path, stream, true);
var uploadedfile = context.Web.GetFileByServerRelativeUrl(path);
context.Load(uploadedfile);
context.ExecuteQuery();

if(uploadedfile.CheckOutType == CheckOutType.None)
{
     uploadedfile.CheckOut();
}

context.ExecuteQuery();
var listitem = uploadedfile.ListItemAllFields;
listitem["column"] = "Value";
listitem.Update();
context.ExecuteQuery();
listitem.File.CheckIn("", CheckinType.MajorCheckIn);
context.ExecuteQuery();

Any help would be appreciated!

3
  • Please try to check-out the file before replacing its content and check-in after replacing its content and properties. Commented Jul 16, 2019 at 13:14
  • Hi Divya thanks for replying, I did try that, I first loaded the uploaded file and then used the SaveBinaryDirect method. However there was no change in the document content.
    – Hank
    Commented Jul 16, 2019 at 13:27
  • I mean checked out the file first and then tried saving it but there was no change
    – Hank
    Commented Jul 16, 2019 at 13:28

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.