none
ClickOnce update .dotx file in Word Template project RRS feed

  • Question

  • Hi,

    I have a C#, MS Word 2007 Template project that I've created in Visual Studio 2010 targetting the 4.0 .NET framework.  I would like to use ClickOnce to deploy the application from a web site.  The initial install is working properly.  I was able to figure out how to copy the .dotx file to the "Workgroup Templates" location on a user's PC, which is a location that is set in our installer.  And I was able to add a shortcut to the Template file to the user's Windows Start Menu.

    The problem I'm having is that during an update or a uninstall, I can't update or remove the .dotx file since MS Word has a lock on the Template file.  I wrote code to detect that Word is running and to prompt the user to exit Word, but when a user tries to quit Word, an error is thrown that says Word can't quit because a dialog box is open.  The dialog box it's referring to is the ClickOnce installation status dialog box.  I somewhat expected this to be the case, but I was hoping that ClickOnce would run outside the Word process and would therefore allow me to quit Word.  Obviously that's not the case.

    I need to update the .dotx file because we have styles defined in the template file.  And it's possible that those style definitions may change over time.

    Does anyone know of a way that I can update/remove the .dotx file during an update/uninstall?

    Again, I have code that will do it all, but since Word has a lock on the file, it doesn't actually work.

    Thanks in advance for the help!

    Wednesday, January 18, 2012 4:29 PM

Answers

  • I was able to cobble together a solution that will work for us.  I'm posting it in case it's useful to others.

    Upon an update, I download the new .dotx file to a temporary location.

    In my ThisDocument.DocumentNew and ThisDocument.DocumentOpen event code, I look for the .dotx file at the temporary location.  If it's there, I open the template file from the workgroup templates location (which is where I copy the .dotx file on an initialinstall) and I copy the styles from the new template file in the temp location into the existing template file and save it.  Then I delete the .dotx file from that temporary location.

    This seems to be working since the ThisDocument.DocumentOpen and/or ThisDocument.DocumentNew code gets executed after the ClickOnce update has completed.

    So, the steps are this:

    1. the user opens a document that's based off my project's template file.
    2. ClickOnce kicks in automagically and determines there's an update available on our web server.
    3. the update is downloaded and installed, placing the new .dotx file in a temporary location. The ClickOnce update finishes and exits.
    4. the ThisDocument.DocumentOpen code is run, where I check for the existence of my .dotx file in the temporary location. If it's there, I copy the styles from the new template into the existing template and save it.  And then I delete the file.

    I hope that's helpful to others.


    • Edited by theLuggage Thursday, January 19, 2012 10:02 PM
    • Marked as answer by theLuggage Thursday, January 19, 2012 10:02 PM
    Thursday, January 19, 2012 10:01 PM

All replies

  • Hi Luggage,

    Thanks for your post.

    We are doing some research on your case right now, please be patient before we can provide some valuable suggestions.

    Good day,


    Calvin Gao[MSFT]
    MSDN Community Support | Feedback to us
    Thursday, January 19, 2012 8:44 AM
    Moderator
  • Another thing I tried to get the update to work was to download the new .dotx file from the web server to a temporary location, open the original .dotx file from the workgoup templates location using Word, and then copy the styles from the new template into the existing template.

    It sort of worked.  I can copy the styles and save the existing Template, but I'm not able to close the Template file.  I get an error that says:

    System.Runtime.InteropServices.COMException (0x8001010A): The message filter indicated that the application is busy. (Exception from HRESULT: 0x8001010A (RPC_E_SERVERCALL_RETRYLATER))
       at Microsoft.Office.Interop.Word.DocumentClass.Close(Object& SaveChanges, Object& OriginalFormat, Object& RouteDocument)
       at PostDeploymentActions.FileHandler.Execute(AddInPostDeploymentActionArgs args)

    I could just leave the Template file open and instruct users to close it, but I'm concerned that they may modify the Template before closing it.


    I've also tried using the OpenXML SDK to copy the styles and put them in the existing Template, I can get a copy of the styles from the new Template, but when I try to put them into the existing Template, I get an error that basically says the Template file is locked by another process.  I'm not too surprised, but I thought I'd give it a try anyway....
    • Edited by theLuggage Thursday, January 19, 2012 4:58 PM
    Thursday, January 19, 2012 2:29 PM
  • Hi theLuggage,

    Your VSTO C#project provides managed code extensions behind the template so it does run in the Word process space. .It doesn’t check for updates until it gets loaded, and that is a consequence of loading the template.

    What you’re trying to do is analogous to asking the window to destroy the house. But the house is holding the window.  Oops – bad analogy. The links below are to content you might find useful.

    VSTO, ClickOnce and auto update
    http://social.msdn.microsoft.com/Forums/en-US/vsto/thread/5370eb94-1ed0-457c-8a39-40ff6d871c12

    Deploying an Office solution using Windows Installer (Mary Lee ...
    http://blogs.msdn.com/b/vsto/archive/2008/04/10/deploying-an-office-solution-using-windows-installer-mary-lee.aspx

    Regards,
    Chris Jensen
    Senior Technical Support Lead


    Chris Jensen
    Thursday, January 19, 2012 5:50 PM
    Moderator
  • I was able to cobble together a solution that will work for us.  I'm posting it in case it's useful to others.

    Upon an update, I download the new .dotx file to a temporary location.

    In my ThisDocument.DocumentNew and ThisDocument.DocumentOpen event code, I look for the .dotx file at the temporary location.  If it's there, I open the template file from the workgroup templates location (which is where I copy the .dotx file on an initialinstall) and I copy the styles from the new template file in the temp location into the existing template file and save it.  Then I delete the .dotx file from that temporary location.

    This seems to be working since the ThisDocument.DocumentOpen and/or ThisDocument.DocumentNew code gets executed after the ClickOnce update has completed.

    So, the steps are this:

    1. the user opens a document that's based off my project's template file.
    2. ClickOnce kicks in automagically and determines there's an update available on our web server.
    3. the update is downloaded and installed, placing the new .dotx file in a temporary location. The ClickOnce update finishes and exits.
    4. the ThisDocument.DocumentOpen code is run, where I check for the existence of my .dotx file in the temporary location. If it's there, I copy the styles from the new template into the existing template and save it.  And then I delete the file.

    I hope that's helpful to others.


    • Edited by theLuggage Thursday, January 19, 2012 10:02 PM
    • Marked as answer by theLuggage Thursday, January 19, 2012 10:02 PM
    Thursday, January 19, 2012 10:01 PM