Find the appointment item associated with a meeting request

This example shows how to use the GetAssociatedAppointment(Boolean) method to find the appointment that is associated with a meeting request.

Example

Note

The following code example is an excerpt from Programming Applications for Microsoft Office Outlook 2007.

A MeetingItem object does not represent an appointment, but a message that contains a request to add an appointment to the recipient’s calendar. In the following code example, MeetingRequestExample uses the GetAssociatedAppointment(Boolean) method of the MeetingItem object on each MeetingItem retrieved from the user’s Inbox. The returned AppointmentItem object is then used to write the subject of the appointment to the trace listeners of the Listeners collection.

Note

Note that GetAssociatedAppointment argument is set to false so that the appointment is not added to the user’s calendar.

If you use Visual Studio to test this code example, you must first add a reference to the Microsoft Outlook 15.0 Object Library component and specify the Outlook variable when you import the Microsoft.Office.Interop.Outlook namespace. The using statement must not occur directly before the functions in the code example but must be added before the public Class declaration. The following line of code shows how to do the import and assignment in C#.

using Outlook = Microsoft.Office.Interop.Outlook;
private void MeetingRequestsExample()
{
    Outlook.Folder folder = Application.Session.
        GetDefaultFolder(Outlook.OlDefaultFolders.olFolderInbox)
        as Outlook.Folder;
    string filter = "[MessageClass] = " +
        "'IPM.Schedule.Meeting.Request'";
    Outlook.Items items = folder.Items.Restrict(filter);
    foreach (Outlook.MeetingItem request in items)
    {
        Outlook.AppointmentItem appt =
            request.GetAssociatedAppointment(false);
        if (appt != null)
        {
            Debug.WriteLine(appt.Subject);
        }
    }
}

See also