Office Online Server - WOPI Interface - Unlocking a file as soon as a file is closed RRS feed

  • Question

  • Hello,

    I have implemented the WOPI Interface with locking and have the following Api method signatures available to me:

    a) public CheckFileInfo GetFileInfo(string fileIdentifier, string access_token, string access_token_ttl);

    b) public HttpResponseMessage Get(string fileIdentifier, string access_token, string access_token_ttl);

    c) public HttpResponseMessage Post(string fileIdentifier);

    d) public async void Post(string fileIdentifier, [FromUri] string access_token, string access_token_ttl);

    (c) is the method used by the OOS client to lock/unlock/refresh lock/Unlock and Relock a file using Request header information.

    My question is:
    When a user is editing a file in Office Online Server, the file is automatically saved using method (d) calls above, however this does not release the lock on the file, as the user may modify an already open file some more, triggering further calls to method (d) above.
    Once a user has finished editing a file, and closes the modal window frame (our implementation) running the OOS word instance, is it possible to make a manual call to unlock the file?
    Currently we rely on the OOS client making this call, which can take sometime, during which no other user can access this file.
    We have also noted that in the mean time if another different file is opened by OOS, it revisits all current locks on previous files that are no longer needed and unlocks them.

    In summary, we are trying to manually unlock the file as soon as we are done editing, but are not sure if we can and should be looking into doing this? If it is possible, please let us know what we need to do, to make this happen.

    Any help and guidance on the issue is much appreciated

    Thank you!


    Saqib Uddin

    Friday, September 15, 2017 2:50 PM


  • Although you can't reduce the autosave frequency, navigation (as seen earlier in this thread with the modal's window.location.href code) will result in OOS sending the final putfile/unlock. 


    Friday, January 4, 2019 10:35 PM

All replies

  • Hi SaqibUddin,

    I can see your issue is related with Office Online.

    this forum only handles the issues regarding Office VBA Object Model.

    so for better response and better solution, I will move this thread to correct and best suitable Office Protocols forum.

    The reason why we recommend posting appropriately is you will get the most qualified pool of respondents, and other partners who read the forums regularly can either share their knowledge or learn from your interaction with us.

    Thank you for your understanding.



    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact

    Monday, September 18, 2017 2:07 AM
  • Hi Saqib , 

    Thanks for your question about explicitly unlocking a file hosted by your WOPI host implementation after closing the Word Online frame. I will gladly look into this for you and get back to you with a full explanation. 

    Best regards,
    Tom Jebo 
    Sr Escalation Engineer
    Microsoft Open Specifications Support

    Monday, September 18, 2017 5:25 AM
  • Some questions, 

    1. is the final unlock request arriving from Word Online ever and just slow or is it that the request never arrives?

    2. are you seeing UnLock requests with invalid lock ids? and if so are you implementing GetLock (which may alleviate this). All this could affect but not completely resolve what you are seeing.

    3. there have been some locking/unlocking issues in previous builds of Office Online (as late as last month) which have since been resolved. Specifically with Word Online. Make sure you are applying updates and have the latest OOS on-prem version. 

    I'll get back to you on issuing post-iframe unlock requests.


    Monday, September 18, 2017 5:41 AM
  • Hi Saqib,

    I've confirmed that the issue in Office Online (cloud) that was preventing unlocks in Word will *not* show up in Office Online Server. 

    Furthermore, the idea of adding extra Unlock calls to what is expected from Office Online Server is not safe. In the interim "delay", there may indeed be changes yet to be pushed. As I mentioned in the other thread, your WOPI host implementation needs to wait for one of two events:

    1. final (PutFile and) Unlock or 

    2. lock expires

    You had said, "Currently we rely on the OOS client making this call, which can take sometime, during which no other user can access this file."

    This is not accurate. The Office web apps are co-authoring capable and therefore other users can still edit if there is an outstanding lock.


    Tuesday, September 19, 2017 9:51 PM
  • Thank you Deepak Panchal10!

    I was looking for the closest match on the topics, but was unable to find anything suitable amongst the long list of topics to post under.

    Thank you for moving the Question under the Office Protocols forum

    • Edited by SaqibUddin Monday, September 25, 2017 1:49 PM
    Monday, September 25, 2017 1:44 PM
  • Thank you for the reply Tom Jebo

    I see that we have to rely on the Office Online Server to make the Unlock request, rather than making a manual intervention and unlocking a file.

    How do we know that the PutFile request made by OOS to the WOPI host is the final PutFile request? 

    I think we may have a problem in the Unlock after the final PutFile request made to the WOPI Host, I shall be retesting this to get the sequence of calls, I shall update in the next reply.

    Monday, September 25, 2017 2:16 PM
  • Yes, it should be the final Unlock. PutFile's without locking should only be received for new file creation (zero byte files). So you should get the final Unlock.

    If you find a problem with Unlock, let me know. 

    Monday, September 25, 2017 7:16 PM
  • This is the content of my log file:


    2017-09-27 12:09:11.9806|INFO|WopiHost.Helpers.WopiAppHelper|GetDocumentLink fullPath= ip1/we/wordeditorframe.aspx?WOPISrc=http%3a%2f%2fip2%3a8890%2fapi%2fwopi%2fFiles%2f1492.docx&access_token=HGkOysnfjrk%3dRaR5v%2fJ%2f63VtYCV60RDTaaLu1lQsAB95GG0fAJpqUJQ%3d&access_token_ttl=0
    2017-09-27 12:09:16.8513|INFO|WopiHost.Controllers.FilesController|Post: wOPIRequestType = Lock
    2017-09-27 12:09:16.8513|INFO|WopiHost.Helpers.WopiLockHelper|Lock1: fileidentifier= 1492.docx
    2017-09-27 12:09:17.0925|INFO|WopiHost.Helpers.WopiLockHelper|Lock3: wopiLock.Value = {"S":"812c9e6f-2ff1-4438-9746-fa8252fbd3a9","F":4}
    2017-09-27 12:09:17.0965|INFO|CCube.BusinessLayer.Service.Client.Logger.LoggerFactory|AddWopiLock, for UserID: 0
    2017-09-27 12:09:19.1770|INFO|WopiHost.Controllers.FilesController|Post: wOPIRequestType = UnlockAndRelock
    2017-09-27 12:09:19.1940|INFO|WopiHost.Helpers.WopiLockHelper|UnLockAndReLock1: fileIdentifier= 1492.docx
    2017-09-27 12:09:19.2510|INFO|WopiHost.Helpers.WopiLockHelper|UnLockAndReLock2: Update the file with a LockValue and LockExpiration
    2017-09-27 12:09:19.2510|INFO|CCube.BusinessLayer.Service.Client.Logger.LoggerFactory|UpdateWopiLock, for UserID: 0


    Notice in the above the last call is to UnlockAndRelock2:  Update the file with a LockValue and LockExpiration. Rather than a GetLock or Unlock call. After this last call, the lock remain on the file. so in my db entry I still have a lock on the file. 

    The DB entry at this point is: 

    ID DocumentID ExpireDate Value
    11 1492 2017-09-27 12:39:19.250 {"S":"812c9e6f-2ff1-4438-9746-fa8252fbd3a9","F":6,"E":2,"M":"f58f033a951e4e8999d608bea6f03e48","P":"875A1CB4-F6A2-496C-991E-2C06EDE13F70"}

    Regards, Saqib Uddin Software Developer | CCube Solutions 

    • Edited by SaqibUddin Wednesday, September 27, 2017 11:23 AM
    Wednesday, September 27, 2017 11:15 AM
  • Without me doing anything, after 8 minutes or so this happens:
    ------------logfile continued ----------
    2017-09-27 12:17:25.3069|INFO|WopiHost.Controllers.FilesController|Post: wOPIRequestType = Unlock
    2017-09-27 12:17:25.3177|INFO|WopiHost.Helpers.WopiLockHelper|UnLock1: fileIdentifier= 1492.docx
    2017-09-27 12:17:25.3302|INFO|WopiHost.Helpers.WopiLockHelper|UnLock2: File lock mismatch...pass Lock in mismatch response
    2017-09-27 12:17:26.5144|INFO|WopiHost.Controllers.FilesController|Post: wOPIRequestType = Unlock
    2017-09-27 12:17:26.6030|INFO|WopiHost.Helpers.WopiLockHelper|UnLock1: fileIdentifier= 1492.docx
    2017-09-27 12:17:26.6174|INFO|WopiHost.Helpers.WopiLockHelper|UnLock2: Unlock the file
    2017-09-27 12:17:26.6174|INFO|CCube.BusinessLayer.Service.Client.Logger.LoggerFactory|UpdateWopiLock, for UserID: 0


    Why is there this delay?

    Sometimes this delay is a lot longer, like half an hour or so. Notice that this unlock happens well after the file has been closed.

    Is this a nromal delay for the file to be unlocked?

    Regards, Saqib Uddin Software Developer | CCube Solutions | 13 Diamond Court | Opal Drive | Fox Milne | Milton Keynes | MK15 0DU | Main Office: +44 (0)1908 677752 | DD: 01908 674007 | Fax: +44 (0)1908 679444 | Web: CCube Solutions is a trading name of OITUK Limited

    • Edited by SaqibUddin Wednesday, September 27, 2017 11:24 AM
    Wednesday, September 27, 2017 11:20 AM
  • Can you also send me a fiddler trace of all of this? This looks more like an expiration. I'd like to see the actual traffic. Send it to, referencing my name and the URL for this thread.



    Wednesday, September 27, 2017 8:55 PM
  • Hey Saqib, 

    I haven't seen anything come through dochelp, have you tried to send traces for me? 


    Tuesday, October 3, 2017 6:50 PM
  • Hello Tom,

    I shall be looking into providing a fiddler trace, just been working on other things.

    Shall email it to you on the email above

    Regards, Saqib Uddin Software Developer CCube Solutions

    • Edited by SaqibUddin Thursday, October 5, 2017 10:55 AM
    Thursday, October 5, 2017 7:59 AM
  • Hello Tom,

    I have sent you an email with a Fiddler Trace for the above.

    Thank you!

    Regards, Saqib Uddin Software Developer CCube Solutions

    Thursday, October 5, 2017 3:26 PM
  • Thank you Saqib, I received the file and will check it out.


    Thursday, October 5, 2017 5:39 PM
  • Sent you a reply in email, the trace doesn't show traffic between the WOPI host and OOS. Can you please try to capture that and resend?


    Thursday, October 5, 2017 8:11 PM
  • Also, I've included a request for ULS logging. Please refer to the email I sent you for instructions.


    Thursday, October 5, 2017 10:14 PM
  • Hello Tom,

    I shall send the ULS logs via email

    Thank you!

    Regards, Saqib Uddin Software Developer CCube Solutions

    Monday, October 16, 2017 4:26 PM
  • Hi Saqib, 

    As we discussed in email, using a modal for the iFrame for Office web apps was a suspect. After my investigation here, I see that it indeed causes the behavior you're seeing wrt the Unlock delays and lock expiration.

    Office web apps are looking for parent page navigation to signal the end of the edit session. In my testing, if I refresh the host page upon closing the modal, I immediately see the Unlock call. 

    // When the user clicks anywhere outside of the modal, close it window.onclick = function (event) { if ( == modal) {

    // navigate or refresh the host page. window.location.href = "http://localhost/SampleHostPage_modal.html"; = "none"; } }

    Adding the above when creating the dialog will have this affect. Of course, in your application, it is likely to be more complex.


    Wednesday, October 18, 2017 11:18 PM
  • To follow on to this explanation, the Unlock upon closing the Word web app is almost immediate and this should resolve the timing/timeliness issues you are seeing. 


    Wednesday, October 25, 2017 4:40 PM
  • Hello Tom and SaqibUddin,

    Hope you are doing great!

    I am also having the same problem while editing any document in office online. I need to update the viewer and generate a PDF from DOCX as soon as user closes the editor Modal window but i am not getting updated Docx file even after waiting for 5 - 6 seconds before generating PDF. 

    Can you Guys please help me to sort out this in case you already found something and implemented. 

    I will really appreciate your help.


    Wednesday, January 2, 2019 12:24 PM
  • Hi Gurpreet,

    [also replied on your other thread]

    Likely the problem is that the host's web app is not navigating away from the Office Online page. Office web app detects this and provides the final PutFile to update the document. Usually, the host's page is navigated to a new host page.

    You can't actually force the PutFile from the host code but it shouldn't be necessary if you properly navigate after the edit session.

    Usually this means navigating to the viewer or to another page.

    The following describes the putfile behavior of Office Online for Word: 

    Another possible reason is related to the file version that needs to be updated and that is described here:

    Hope this helps,


    Wednesday, January 2, 2019 5:59 PM
  • Hello Tom, 

    Thanks for your reply.

    Is there any way we can make sure that the document is updated with the latest changes after closing the modal popup. We are using a custom UI button to close the modal. We generate a PDF from the Docx file right after closing the modal. We are not redirecting host page to anywhere but just hiding it.

    Also, Can we reduce the autosave frequency time for the online word from the host or server?


    Thursday, January 3, 2019 11:39 AM
  • I also tried your solution to redirect host page to something else after making changes in Docx but still, it is not giving me updated file content and we are seeing old PDF. 
    Thursday, January 3, 2019 2:20 PM
  • No you can't reduce the autosave freqency. Are you updating the version of the file in CheckFileInfo and recalculating the SHA256 value?


    Thursday, January 3, 2019 6:08 PM
  • Although you can't reduce the autosave frequency, navigation (as seen earlier in this thread with the modal's window.location.href code) will result in OOS sending the final putfile/unlock. 


    Friday, January 4, 2019 10:35 PM
  • If you still need assistance, please send an email to dochelp at referencing the URL for this (or the other) thread and my name. I will likely need to make arrangements to gather data from you.



    Monday, January 7, 2019 6:15 PM
  • Hello Tom,

    Thanks for all your help. I really appreciate it.

    Navigation worked fine and i got final unlock. Its all working fine with editing now but i am stuck with PutRelativeFile. Server is not sending PutRelativeFile request to wopihost. Its showing a message that file is being converted with spinner but nothing is actually converting. I am not getting logs for PutRelativeFile requests. 

    Could you please assist me in this.

    Thanks in advance.


    Tuesday, January 8, 2019 2:20 PM
  • Hi Gurpreet, 

    Thanks for confirming. For the PutRelativeFile problem, what conversion is taking place? Is your host invoking the convert action explicitly and if so, which file type? 


    Tuesday, January 8, 2019 11:26 PM
  • Hello Tom,

    We are trying to convert Doc into Docx but we are not getting PutRelativeFile request to host at all. There are no logs for this request. When we invoke convert URL like below:


    we don't get any logs for PutRelativeFile action on the Wopi Host. How it will work?

    or how can we make it work? Could you please assist me in this.

    Thanks for your support.


    Wednesday, January 9, 2019 7:45 AM
  • Are you using Office Online Server 2016 or Office Web Apps Server 2013?

    Please send an email to dochelp at microsoft dot com (reference this thread's URL and my name) and I'll gather some more information to assist you.


    Wednesday, January 9, 2019 6:09 PM
  • Hello Tom,

    Yes, That is me only who you are connected to on gmail.



    Friday, January 11, 2019 7:31 AM
  • Hi @gurupreet Rajpal,

    I'm facing same issue and need your help to solve it as how you have solved it by navigating .



    Monday, June 15, 2020 3:48 PM