How to checkin major version inside Word using VSTO
-
13-01-2021 - |
题
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:-
Please refer thread discussing server side implementation of this below:-