none
Insert in Inline Responses not visible RRS feed

  • Question

  • For inline responses, when you try to use any Insert function, whatever you insert (be it text or a file) does not appear until you click pop out or revisit the mail later in the Drafts folder.


    This bug is very easy to recreate.   Just make a new add on for Outlook 2013 using Visual Studio 2013.  Add a reference to Microsoft.Office.Interop.Word.  Then just modify the start up function as follows:

            private void ThisAddIn_Startup(object sender, System.EventArgs e)
            {
                Application.Explorers.NewExplorer += Explorers_NewExplorer;
                foreach (var explorer in Application.Explorers.OfType<Outlook.Explorer>())
                {
                    explorer.InlineResponse += ThisAddIn_InlineResponse;
                }
            }

            private void Explorers_NewExplorer(Outlook.Explorer explorer)
            {
                explorer.InlineResponse += ThisAddIn_InlineResponse;
            }

            void ThisAddIn_InlineResponse(object Item)
            {
                var mailItem = Item as Outlook.MailItem;
                if (mailItem == null)
                    return;
                var document = mailItem.GetInspector.WordEditor;
                var insertRange = document.Paragraphs.First.Range as Range;
                insertRange.InsertBefore("Test Text");
            }

    Friday, March 28, 2014 5:47 PM

Answers

  • Hi,

    According to your description, you want to edit the context the mail item when using inline response feature.

    In fact, for inline responses, the reading pane is editable to allow users to reply inline, which is different from opening new Inspector windows. So we should resort to Explorer.ActiveInlineResponseWordEditor Property to access and edit the main item content rather than Inspector.WordEditor Property which is for the mail item in inspector windows.

    Here is a sample for your reference and it works well.

    void ThisAddIn_InlineResponse(object Item)
    {
        var mailItem = Item as Outlook.MailItem;
        Explorer exp = Globals.ThisAddIn.Application.ActiveExplorer();
        if (mailItem == null)
            return;
        Word.Document uiDoc = exp.ActiveInlineResponseWordEditor as Word.Document;
        if (uiDoc != null)
        {
            Word.Range insertRange = uiDoc.Paragraphs.First.Range;
            insertRange.InsertBefore("Test Text");
        }
    } 


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    • Marked as answer by Matthew3 Monday, March 31, 2014 9:19 AM
    Monday, March 31, 2014 7:02 AM
    Moderator

All replies

  • Hello Matthew,

    Did you try to debug the code? Is the InlineResponse event fired?

    The fact is that you subscribe to event of the reference which is swiped when the method ends (however, the actual time depends on the garbage collector GC):

    Application.Explorers.NewExplorer += Explorers_NewExplorer;


    I'd recommend declaring a class level Explorers reference and subscribing to the event of the global variable which is alive all the time, not released when the method ends. Thus, you can be sure that event will be handled in your code.

    Also I see that you use the foreach loop:

    foreach (var explorer in Application.Explorers.OfType<Outlook.Explorer>())

    Use the for loop instead. It will allows to release COM objects instantly. Use System.Runtime.InteropServices.Marshal.ReleaseComObject to release an Outlook object when you have finished using it. Then set a variable to Nothing in Visual Basic (null in C#) to release the reference to the object. Read more about this in the Systematically Releasing Objects article.


    Friday, March 28, 2014 5:53 PM
  • Hi,

    According to your description, you want to edit the context the mail item when using inline response feature.

    In fact, for inline responses, the reading pane is editable to allow users to reply inline, which is different from opening new Inspector windows. So we should resort to Explorer.ActiveInlineResponseWordEditor Property to access and edit the main item content rather than Inspector.WordEditor Property which is for the mail item in inspector windows.

    Here is a sample for your reference and it works well.

    void ThisAddIn_InlineResponse(object Item)
    {
        var mailItem = Item as Outlook.MailItem;
        Explorer exp = Globals.ThisAddIn.Application.ActiveExplorer();
        if (mailItem == null)
            return;
        Word.Document uiDoc = exp.ActiveInlineResponseWordEditor as Word.Document;
        if (uiDoc != null)
        {
            Word.Range insertRange = uiDoc.Paragraphs.First.Range;
            insertRange.InsertBefore("Test Text");
        }
    } 


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    • Marked as answer by Matthew3 Monday, March 31, 2014 9:19 AM
    Monday, March 31, 2014 7:02 AM
    Moderator
  • Thank you for your answer.  This is exactly what I was looking for.
    Monday, March 31, 2014 9:31 AM