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?

有帮助吗?

解决方案

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

许可以下: CC-BY-SA归因
scroll top