0

I need help with Sharepoint CSOM. I have used this

using Microsoft.SharePoint.Client;
//removed code
var context = new ClientContext(myURl);
var file = context.Web.GetFileByServerRelativeUrl(FileUrl);
file.CheckOut();

var libraryFields = file.ListItemAllFields;

libraryFields["Title"] = "My title";
libraryFields.Update();

file.CheckIn(string.Empty, CheckinType.OverwriteCheckIn);

context.ExecuteQuery();

when I run the above code I get the following error:

The file "https://****.sharepoint.com/sites/myfile.tif" is checked out for editing by i:0#.f|membership|[email protected]

Can anyone please tell me what is going wrong in my code.

2
  • You can try to do a context.ExecuteQuery(); before file.CheckIn (but keep the last one as well) and see if that makes any difference Mar 30, 2020 at 11:17
  • context.load(file) before you checout Mar 30, 2020 at 11:49

1 Answer 1

0

Try to add the below code, before executing the context.ExecuteQuery() publish and load the file and also check for it is not checked out.

if (file.CheckOutType != CheckOutType.None)
{
       file.CheckIn("Check in comment": "", checkInType: CheckinType.MajorCheckIn);
            file.Publish(comment: "");

            context.Load(file);
            context.ExecuteQuery(); 
}

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.