0

I'm trying to prevent any data change for a file using CSOM, but even after checking out the file, the UI still allows update/deletion/rename. Is there a way to prevent this, i e to lock/checkout the file so that it could not be editing in any way?

My code looks like this:

          SPClient.File newFile =
                context.Web.GetFileByServerRelativePath(serverRelative);

            context.Load(newFile, f => f.CheckOutType);
            context.ExecuteQuery();

            if (newFile.CheckOutType == SPClient.CheckOutType.None)
            {
                newFile.CheckOut();                    
                context.Load(newFile);
                context.ExecuteQuery();
            }
0

I think by performing a Load immediately after you call CheckOut(), you are erasing your checkout.

When you call Checkout() from CSOM, it does not take affect until you call ExecuteQuery(). But whenever you call Load(someobj), the next call to ExecuteQuery() will load that object's existing server-side properties into your client-side copy, erasing any changes you may have made to the client-side object. It's kind of the equivalent of starting to fill out an online form, then refreshing the page before you hit the submit button.

Try changing to:

SPClient.File newFile = context.Web.GetFileByServerRelativePath(serverRelative);

context.Load(newFile, f => f.CheckOutType);
context.ExecuteQuery();

if (newFile.CheckOutType == SPClient.CheckOutType.None)
{
    newFile.CheckOut();   
    context.ExecuteQuery();
}
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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