You do not have to initialize a new instance of Outlook.Application() every time. Most add-in infrastructures provide you with an instance of Outlook.Application that matches the current Outlook session, usually through a field or property named Application . You are expected to use this for the life of your add-in.
To get the selected item, use:
Outlook.Explorer explorer = this.Application.ActiveExplorer(); Outlook.Selection selection = explorer.Selection; if (selection.Count > 0) // Check that selection is not empty. { object selectedItem = selection[1]; // Index is one-based. Outlook.MailItem mailItem = selectedItem as Outlook.MailItem; if (mailItem != null) // Check that selected item is a message. { // Process mail item here. } }
Please note that the above will allow you to process the first selected item. If you have selected multiple elements, you can process them in a loop.
Douglas
source share