Reputation: 127
I want to write an add-in for Outlook 2010. The idea is - user selects one mail item in folder, then presses the button on ribbon which starts the add-in. Add-in gets information from selected item, process it and displays result. I run in to problems when trying to get the Inspector of selected item. I tried:
Outlook.Inspector Point = this.Application.ActiveInspector().CurrentItem as Outlook.Inspector;
Outlook.MailItem mailItem = Point.CurrentItem as Outlook.MailItem;
Of course this doesn't check if current item is actually an mail item but that's for later. My problem is, when i try running the program i get NullReferenceException. The only working examples of this I found on web was with event handling. But I want to start add-in on button press..
I am trying to make this in .NET 3.5 not 4
Upvotes: 3
Views: 10691
Reputation: 39
Globals.ThisAddIn.Application to get the Application object. That's probably your null reference, there is no Application object on "this" within the ribbon class.
Upvotes: 3
Reputation: 11227
here is the link that helped me a lot to sort out Outlook interop issues: http://msdn.microsoft.com/en-us/library/ff184621.aspx - and it does show how to enumerate currently selected items as well.
Upvotes: 0
Reputation: 31651
The ActiveInspector()
is the window that opens when the user double-clicks a mail item in the Explorer
window. If the user is just viewing MailItems
in the reading pane - you won't have an active inspector window (hence the NullReferenceException
).
You are probably looking for the Explorer.Selection
to get access to the currently selected MailItems
.
Outlook.Selection selection = this.Application.ActiveExplorer().Selection;
Upvotes: 5