Understanding the events in the Outlook object model is critical because this is often the primary way that your code is run. This chapter covers many of the events in the Outlook object model, when they are raised, and the type of code you might associate with these events.
Outlook associates the same set of events with all the Outlook item object types listed in Table 10-1. In this chapter, we will refer to Item events, but there is no Item object per se in the Outlook object model. Instead, you will find the same set of Item events (defined by ItemEvents_10_Event interface) on each of the 15 Outlook object model objects listed in Table 10-1.
Object |
Description |
---|---|
AppointmentItem |
An appointment item typically found in the Calendar folder. |
ContactItem |
A contact item typically found in the Contacts folder. |
DistListItem |
A distribution list typically found in the Contacts folder. |
DocumentItem |
A document that you have added to an Outlook folder by dragging and dropping it from the file system into the Outlook folder. |
JournalItem |
A journal entry typically found in the Journal folder. |
MailItem |
A mail message typically found in the Inbox folder. |
MeetingItem |
A meeting request typically found in the Inbox folder. |
NoteItem |
A note typically found in the Notes folder. |
PostItem |
A post in an Outlook folder. |
RemoteItem |
A mail message that has not yet been fully retrieved from the server but has the subject of the message, the received date and time, the sender, the size of the message, and the first 256 characters of the message body. |
ReportItem |
A mail delivery report such as a report when mail delivery failed typically found in Outlook's Inbox folder. |
TaskItem |
A task typically found in the Tasks folder. |
TaskRequestAcceptItem |
A response to a TaskRequestItem typically found in the Inbox folder. |
TaskRequestDeclineItem |
A response to a TaskRequestItem typically found in the Inbox folder. |
TaskRequestItem |
A task request sent to another user typically found in the Inbox folder. |
TaskRequestUpdateItem |
An update to a TaskRequestItem typically found in the Inbox folder. |
Why Are There Multiple Event Interfaces?
When you work with the Outlook object model, you will quickly notice multiple public interfaces, classes, and delegates associated with events:
The only elements from this list that you should ever use in your code are the ones in bold text. The *_Event interfaces in bold should only be used when you have to cast an object to its corresponding event interface because a method name and event name collide. An example of this is the Inspector object, which has both a Close method and a Close event. To disambiguate between the two, you have to cast the Inspector object to InspectorEvents_10_Event when you want to handle the Close event.
Chapter 1, "An Introduction to Office Programming," briefly explains the reason for the other items in this list. However, this explanation only explains the SinkHelper class and why there is both an ObjectEvents interface and an ObjectEvents_Event interface. The reason there are multiple numbered events associated with some objects goes back to the original COM implementation of the Outlook object model.
Outlook's Application, Explorer, Inspector, and Item COM objects have had their event interfaces defined over multiple versions. For example, consider the Application events. Events defined in Outlook XP for the Application object are on the interface named ApplicationEvents_Event. Events that were new in Outlook 2000 are on the interface named ApplicationEvents_10_Events. (Outlook 2000 was known internally at Microsoft as Outlook 10.) ApplicationEvents_10_Events also contains all the events that are in the ApplicationEvents_Event. Events that were new in Outlook 2003 are on the interface named ApplicationEvents_11_Events. (Outlook 2003 was known internally at Microsoft as Outlook 11.) The ApplicationEvents_11_Events interface includes all the events defined in Outlook XP and Outlook 2000. Because ApplicationEvents_11_Events contains all the events defined for Application, this is the only interface you should use for Outlook 2003 development.
Part One. An Introduction to VSTO
An Introduction to Office Programming
Introduction to Office Solutions
Part Two. Office Programming in .NET
Programming Excel
Working with Excel Events
Working with Excel Objects
Programming Word
Working with Word Events
Working with Word Objects
Programming Outlook
Working with Outlook Events
Working with Outlook Objects
Introduction to InfoPath
Part Three. Office Programming in VSTO
The VSTO Programming Model
Using Windows Forms in VSTO
Working with Actions Pane
Working with Smart Tags in VSTO
VSTO Data Programming
Server Data Scenarios
.NET Code Security
Deployment
Part Four. Advanced Office Programming
Working with XML in Excel
Working with XML in Word
Developing COM Add-Ins for Word and Excel
Creating Outlook Add-Ins with VSTO