Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All
Expand Minimize
Important This document may not represent best practices for current development, links to downloads and other resources may no longer be valid. Current recommended version can be found here.

How to: Determine the Current Outlook Item

Note Required applications

The code example in this topic can be compiled only if you have the required applications installed.

For more information, see Features Available by Product Combination.

  • One of these development environments:

    VSTO 2005


    Visual Studio Team System

  • Microsoft Office Outlook 2003


This code does not compile if you use the VSTO 2005 SE version of the Outlook 2003 add-in project template. For more information, see Getting Started Programming Application-Level Add-ins.

This example uses the Explorer.SelectionChange event to display the name of the current folder and some information about the selected item. The code then displays the selected item.


Outlook.Explorer currentExplorer = null;

private void ThisApplication_Startup
    (object sender, System.EventArgs e)
    currentExplorer = this.ActiveExplorer();
    currentExplorer.SelectionChange += new Outlook

private void CurrentExplorer_Event()
    Outlook.MAPIFolder selectedFolder = 
    String expMessage = "Your current folder is " 
        + selectedFolder.Name + ".\n";
    String itemMessage = "Item is unknown.";
        if (this.ActiveExplorer().Selection.Count > 0)
            Object selObject = this.ActiveExplorer().Selection[1];
            if (selObject is Outlook.MailItem)
                Outlook.MailItem mailItem = 
                    (selObject as Outlook.MailItem);
                itemMessage ="The item is an e-mail message." +
                    " The subject is " + mailItem.Subject + ".";
            else if (selObject is Outlook.ContactItem)
                Outlook.ContactItem contactItem = 
                    (selObject as Outlook.ContactItem);
                itemMessage = "The item is a contact." + 
                    " The full name is " + contactItem.Subject + ".";
            else if (selObject is Outlook.AppointmentItem)
                Outlook.AppointmentItem apptItem = 
                    (selObject as Outlook.AppointmentItem);
                itemMessage = "The item is an appointment." + 
                    " The subject is " + apptItem.Subject + ".";
            else if (selObject is Outlook.TaskItem)
                Outlook.TaskItem taskItem = 
                    (selObject as Outlook.TaskItem);
                itemMessage = "The item is a task. The body is " 
                    + taskItem.Body + ".";
            else if (selObject is Outlook.MeetingItem)
                Outlook.MeetingItem meetingItem =
                    (selObject as Outlook.MeetingItem);
                itemMessage = "The item is a meeting item. " +
                     "The subject is " + meetingItem.Subject + ".";
    expMessage = expMessage + itemMessage;
    catch (Exception ex)
    expMessage = ex.Message;

Compiling the Code

This example requires:

  • Appointment, contact, and e-mail items in Microsoft Office Outlook.

See Also

Community Additions

© 2015 Microsoft