Outlook add-in, RibbonType Microsoft.Outlook.Explorer and Microsoft.Outlook.Mail.Read

I have an Outlook 2010 add-in encoded in .NET 4.0 / VS.NET 2010, C #. The add-in extends the ribbon => it adds a RibbonTab with 4 RibbonButtons to the ( RibbonType property set) Microsoft.Outlook.Explorer and Microsoft.Outlook.Mail.Read .

Now, if the user clicks on one of the RibbonButtons, how can I determine if the user clicked the button that was added to Microsoft.Outlook.Explorer OR Microsoft.Outlook.Mail.Read ?

+4
source share
2 answers

One option is to create (2) tapes with a common library of features. When you call your shared library, you can pass in the context by which the tape action was clicked.

A better choice is to check the application’s ActiveWindow property to determine in which context the user is through ThisAddin.Application.ActiveWindow() .

  var windowType = Globals.ThisAddin.Application.ActiveWindow(); if (windowType is Outlook.Explorer) { Outlook.Explorer exp = type as Outlook.Explorer; // you have an explorer context } else if (windowType is Outlook.Inspector) { Outlook.Inspector exp = type as Outlook.Inspector; // you have an inspector context } 
+3
source

SilverNinja's offer pointed me in the direction. Finally, my code:

  // get active Window object activeWindow = Globals.ThisAddIn.Application.ActiveWindow(); if (activeWindow is Microsoft.Office.Interop.Outlook.Explorer) { // its an explorer window Outlook.Explorer explorer = Globals.ThisAddIn.Application.ActiveExplorer(); Outlook.Selection selection = explorer.Selection; for (int i = 0; i < selection.Count; i++) { if (selection[i + 1] is Outlook.MailItem) { Outlook.MailItem mailItem = selection[i + 1] as Outlook.MailItem; CreateFormOrForm(mailItem); } else { Logging.Logging.Log.Debug("One or more of the selected items are not of type mail message..!"); System.Windows.Forms.MessageBox.Show("One or more of the selected items are not of type mail message.."); } } } if (activeWindow is Microsoft.Office.Interop.Outlook.Inspector) { // its an inspector window Outlook.Inspector inspector = Globals.ThisAddIn.Application.ActiveInspector(); Outlook.MailItem mailItem = inspector.CurrentItem as Outlook.MailItem; CreateFormOrForm(mailItem); } 

Maybe this helps someone else ...

+5
source

All Articles