1

I'm developing a Word VSTO so, when a user opens a document from Sharepoint and presses a button, the code should create a major version. The code is:

Globals.ThisAddIn.Application.ActiveDocument.Close();
.....
Microsoft.SharePoint.Client.File file = web.GetFileByServerRelativeUrl(fileServerRelativeUrl); 
ctx.Load(file);
ctx.ExecuteQuery();
file.CheckIn("updated by user: "+Environment.UserName, CheckinType.MajorCheckIn);
file.Update();
ctx.ExecuteQuery();


I get an error: The file http://myserver/Firm_/fillee11.docx is locked for shared use by ADname\the_same_user_whois_loggedOntoPC. So, what is the proper way to check in the file?

1

When the file is opened from SharePoint directly via any of the office application, SharePoint locks the file for short term. The lock is released automatically by SharePoint after certain duration (idle timeout). There is a server side API - "ReleaseLock" that can be used to explicitly release the lock.

No client side/REST API is available as of now for this.

You can vote to suggest this feature below:-

https://sharepoint.uservoice.com/forums/329214-sites-and-collaboration/suggestions/18430918-ability-to-remove-short-term-lock-in-csom-rest-api

Please refer thread discussing server side implementation of this below:-

Clearing short term file lock

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.