locked
Outlook 2013 Events RRS feed

  • Question

  • Hi Gavin,

    I stumbled over your blog post "Updating NoReplyAll for Outlook 2013" while trying to update my own add-in to handle the InlineResponse. The reflections approach is a great idea, but I have problems with the implementation (see example code below).

    I don't get any exceptions (and einfo is not null) but neither does the InlineResponse-event trigger my method.

    It would be great if you could tell me what I'm missing.

    public partial class ThisAddIn
    {
       Outlook.Explorer _explorer;
    
       private void ThisAddIn_Startup(object sender, System.EventArgs e)
       {
           _explorer = Application.ActiveExplorer();
    
           AddInlineResponseHandler();
       }
    
       private void AddInlineResponseHandler()
       {
          var einfo = _explorer.GetType().GetEvent("InlineResponse", BindingFlags.Public | BindingFlags.Instance);
    
          if (einfo != null)
          {
             var handler = Delegate.CreateDelegate(einfo.EventHandlerType, this, this.GetType().GetMethod("OnInlineResponse", BindingFlags.NonPublic | BindingFlags.Instance), false);
    
             einfo.AddEventHandler(_explorer, handler);
          }
    
       }
    
       private void OnInlineResponse()
       {
          System.Windows.Forms.MessageBox.Show("InlineResponse");
       }
    }

    Friday, May 3, 2013 6:52 AM

Answers

  • The only difference I can spot between yours and mine is that OnInlineResponse takes an argument, the newly created mail item - see http://msdn.microsoft.com/en-us/library/office/jj229061 - ie, my method is defined as:

    private void OnInlineResponse(object item)
    {
      ...
    }

    Not entirely sure why there was no error indication (unless this is Outlook doing its best to prevent add-ins from crashing the application).

    Do let me know if that fixed things.

    If it doesn't, it might be worth trying the normal non-reflection route (which will need the latest VSTO) - once that's working, then you ought to be able to replace the "_explorer.InlineResponse += OnInlineResponse" with the reflection code. (Another idea, though I've not tested this, might be to use that non-reflection syntax, but put it inside a try-catch handler - I would expect the reference to InlineResponse to throw an exception on older versions of Outlook.)

    Friday, May 3, 2013 12:12 PM

All replies

  • The only difference I can spot between yours and mine is that OnInlineResponse takes an argument, the newly created mail item - see http://msdn.microsoft.com/en-us/library/office/jj229061 - ie, my method is defined as:

    private void OnInlineResponse(object item)
    {
      ...
    }

    Not entirely sure why there was no error indication (unless this is Outlook doing its best to prevent add-ins from crashing the application).

    Do let me know if that fixed things.

    If it doesn't, it might be worth trying the normal non-reflection route (which will need the latest VSTO) - once that's working, then you ought to be able to replace the "_explorer.InlineResponse += OnInlineResponse" with the reflection code. (Another idea, though I've not tested this, might be to use that non-reflection syntax, but put it inside a try-catch handler - I would expect the reference to InlineResponse to throw an exception on older versions of Outlook.)

    Friday, May 3, 2013 12:12 PM
  • Aaaaand... it works :)

    Thank you very much for replying and even more for solving my problem: the addition of the argument was indeed the solution.

    Thanks again!

    Friday, May 3, 2013 12:58 PM