none
ThisAddIn_StartUp is not executed when open ms word template using VSTO from SharePoint 2010 RRS feed

  • Question

  • Hi,

    i have created several ms word templates, these templates will be triggered using vsto. the vsto is an application level add-in. i already uploaded the template into a sharepoint library, after that i created a custom webpart which is linked to the document templates. on the webpart i show several icons for the templates.

    the idea is whenever i click the template icon on the webpart, ms word will load and i can use the vsto add-in inside the ms word template. since this is an application level add-in, the custom ribbon which i created is shown, but it seems like my method in ThisAddIn_StartUp was not executed, because the code validation for the ribbon is not fired and a custom task pane on the left side which should be shown is not visible.

    this add-in works fine if i trigger to open document from outlook (i also create an add-in in outlook that can open the ms word templates)

    could somebody please tell me what went wrong?

    any help would be very much appreciated.

    thanks.


    -Regards- Willy Noviandy

    Thursday, March 8, 2012 8:25 AM

All replies

  • 1. Add some erro handling/logging to your startup event to be sure no error escaped without your knowledge.

    2. How do you open word when user clicks icon in your webpart? what js function do you execute?

    Thursday, March 8, 2012 8:54 AM
  • Hi Damian,

    1. i already did add some logging and i tried to attach the process and debug it, but it seemed like the startup event is not even called at all.

    2. i use the native sharepoint js which is --> createNewDocumentWithProgID

    any idea?

    thanks.


    -Regards- Willy Noviandy

    Thursday, March 8, 2012 9:04 AM
  • works fine here, but we use:

    editDocument = new ActiveXObject("SharePoint.OpenDocuments.3"); 
    editDocument.EditDocument(url);
    
    

    maybe try something like this?
    Thursday, March 8, 2012 11:52 AM
  • Hi Damian,

    sorry, i've been away for a while.

    updates :

    the ThisAddIn_StartUp is triggered, but the application document open method which is fired from the ThisAddIn_StartUp won't get executed.

    i try to show a message box to check whether if it is triggered or not, but my messagebox is not shown.

    this is my ThisAddin_StartUp method :

    private void ThisAddIn_Startup(object sender, System.EventArgs e)
            {
                try
                {
                    ButtonDisableAll();
                    MessageBox.Show("ThisAddIn_Startup is fired");
                    //Globals.ThisAddIn.Application.WindowState = Word.WdWindowState.wdWindowStateMaximize;                    
                    this.Application.DocumentBeforeSave += new Microsoft.Office.Interop.Word.ApplicationEvents4_DocumentBeforeSaveEventHandler(Application_DocumentBeforeSave);
                    this.Application.DocumentOpen += new Word.ApplicationEvents4_DocumentOpenEventHandler(Application_DocumentOpen);
                    MessageBox.Show("Trying to open the document");
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message + "ThisAddIn_Startup Exception");
                }
            }

    this is my application document open method :

    void Application_DocumentOpen(Word.Document wDoc)
            {
                MessageBox.Show("Opening the Document");
                try
                {
                    string usrname = System.Environment.UserDomainName.ToString() + "\\" + System.Environment.UserName.ToString();
    
                    MessageBox.Show(usrname);
    
                    if (Utilities.getContentControl(wDoc, Utilities.ccdispTitle) != null)
                    {
                        MessageBox.Show("Getting content control");
                        string StatusDocText = string.Empty;
                        //Word.Application wApp = Globals.ThisAddIn.Application;
                        //Word.Document wDoc = wApp.ActiveDocument;
                        wDoc.Application.WindowState = Word.WdWindowState.wdWindowStateMaximize;
                        wDoc.ActiveWindow.ActivePane.View.Zoom.Percentage = 100;
                        string DocName = wDoc.Name;
                        MessageBox.Show("Getting active document");

    now, it seems like the add in does not recognize any word document being opened. this still occurs only when i open my document template from sharepoint, besides that, it worked just fine.

    any idea?

    Thanks.


    -Regards- Willy Noviandy


    • Edited by Wie Lie Monday, March 19, 2012 9:47 AM add explanation
    Monday, March 19, 2012 9:44 AM
  • Startup event works but DocumentOpen does not? try commenting out everyting in DocumentOpen and leave only first call to MessageBox. Does it work now?
    Monday, March 19, 2012 10:12 AM
  • Hi Damian,

    i tried what you said, but still doesn't work.

    i leave only the first call to show the messagebox, but it doesn't appear.

    any idea?

    Thanks.


    -Regards- Willy Noviandy

    Monday, March 19, 2012 10:29 AM
  • When do you expect this DocumentOpen to fire? If you open document from sharepoint and inside that word window click Open document and open up some other doc - will this event fire?

    Monday, March 19, 2012 10:51 AM
  • Hi Damian,

    the DocumentOpen should be triggered when i open the template from the outlook add in which i created.

    the scenario is, i click a button from my custom outlook add-in, and then it will trigger the word template to open. when it does, it will trigger the DocumentOpen method.

    hmm.. did i miss something?

    i realized when i open the template manually (double clicking the template) the same behaviour occur like when i open it from sharepoint.

    i have this code on my outlook add-in button to trigger the template to open :

    private void btnNewMemo_Click(object sender, RibbonControlEventArgs e)
            {
                try
                {
                    WordApp = new Word.Application();
                    object fileName = strRootPath + "Memo.dotx";
                    object readOnly = false;
                    object isVisible = true;
                    // Here is the way to handle parameters you don't care about in .NET
                    object missing = System.Reflection.Missing.Value;
                    // Make word visible, so you can see what's happening
                    // Open the document that was chosen by the dialog
                    Word.Document aDoc = WordApp.Documents.Open(ref fileName, ref missing, ref readOnly, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref isVisible);
    
                    // Activate the document so it shows up in front
                    WordApp.Visible = true;
                    WordApp.Activate();
                    aDoc.Activate();
                }
                catch (System.Exception ex)
                {
                }
                finally
                {
                    System.Runtime.InteropServices.Marshal.ReleaseComObject(WordApp);
                    //System.Runtime.InteropServices.Marshal.ReleaseComObject(aDoc);
                }
            }

    any idea?

    Thanks.


    -Regards- Willy Noviandy

    Monday, March 19, 2012 11:08 AM
  • is it necessary to start up new word to show your document? try calling open on your current word app - will event handler be triggered? 
    Monday, March 19, 2012 11:22 AM
  • Hi Damian,


    so you mean that i have to change this :


    this.Application.DocumentOpen += new Word.ApplicationEvents4_DocumentOpenEventHandler(Application_DocumentOpen);

    into open current word app?

    hmm.. some hint maybe? i don't have any idea what to add or what to change.

    :(


    -Regards- Willy Noviandy

    Monday, March 19, 2012 1:52 PM
  • no, change function btnNewMemo_Click to _not_ start up new word process, but use exisitng one. Call Open function there on existing Application object, not a newly created one.
    Monday, March 19, 2012 2:08 PM