Microsoft Office Outlook Programming Using VSTO 3.0 and C#: Part 2

4 min read

Working with Appointments

Before we start working with the Appointments feature in Microsoft Office Outlook 2007, let’s take a look at the Microsoft Office Outlook calendar. This will help you understand the concepts of Appointments more easily, and also explain how you can utilize this functionality for your needs. The Microsoft Outlook 2007 calendar is the scheduling component of the Outlook mail management system. It is well-integrated with other Microsoft Outlook functionality such as email, contacts, appointments, and other items in.

Appointments are the actions you’re scheduling in your Outlook calendar, inviting other people to participate if required. You can set the status of your availability for an appointment, and you can also schedule recurring appointments.

Let’s create an Outlook Appointment dynamically by using VSTO objects and C# programming:

  1. Open Visual Studio 2008, to create a new Outlook 2007 Add-in template project.
  2. Select New Project. Under Office select 2007 and select Outlook 2007 Add-in template and name the project as per your requirement.
  3. The solution will be created with all of supporting files required for the development of our Outlook solution.
  4. Write the following code, which will dynamically create an Appointment item in the ThisAddIn.cs file:
    private void ThisAddIn_Startup(object sender, System.EventArgs e)
    // Outlook AppointmentItem object to compose new Appointment
    Outlook.AppointmentItem PacktAppointmentItem = (Outlook.
    // Set the subject property value
    PacktAppointmentItem.Subject = "Regarding book review";
    // Set the location property value
    PacktAppointmentItem.Location = "Meeting Hall";
    // Set the start date
    PacktAppointmentItem.Start = DateTime.Today;
    // Set the end date
    Pac ktAppointmentItem.End = DateTime.Today;
    // Set the body property value
    PacktAppointmentItem.Body = "Book review comments from
    all editors";
    // Set the required attendee information
    PacktAppointmentItem.RequiredAttendees = "";
    // Set the optional attandee information
    PacktAppointmentItem.OptionalAttendees = "";
    // If parameter is set to false compose Appointment won't display
    // To send the composed PacktAppointmentItem

The following screenshot shows the results of adding and executing this code:

VSTO 3.0 for Office 2007 Programming

The AppointmentItem object is used to create appointments dynamically. An AppointmentItem object can be used to create a meeting, a one-time appointment, or a recurring appointment.

Let’s perform a demonstration of how to delete a recurring appointment from your Outlook 2007 calendar, by using VSTO programming.

Open Visual Studio 2008 and create a new solution, as described earlier. Write the following code, which will dynamically delete an Appointment item, inside the ThisAddIn.cs file:

private void ThisAddIn_Startup(object sender, System.EventArgs e)
// Reading the calendar folder through MEPIFolder object
Outlook.MAPIFolder PacktCalendarInfo = Application.Session.
// Get the data items in the calendar folder
Outlook.Items PacktCalendarDataItems = PacktCalendarInfo.Items;
// Searching the Appointment items based on subject
Outlook.AppointmentItem PacktAppointmentItem =
PacktCalendarDataItems["Book release"] as Outlook.
// Selected appointment's recurrence information
Outlook.RecurrencePattern PacktRecPattern = PacktAppointmentItem.
// Loading the appointment to AppointmentItem Object
Outlook.AppointmentItem PacktAppointmentDelete = PacktRecPattern.
GetOccurrence(new DateTime(2008, 9, 28, 8, 0, 0));
// Now delete using the Delete method

Working with meetings

Meetings are generally discussions amongst more than two people, during which predetermined topics are discussed. Meetings help you prepare a plan, or finalize pending work, or perform other tasks involving colleagues. In Microsoft Office Outlook, a meeting is a scheduled appointment—that is, people are invited to attend. You can set the meeting time and other options for the meeting attendees, to process the invitation.

VSTO 3.0 supports the dynamic creation of meeting items for Office. Let’s create a meeting invitation dynamically, by using the VSTO object model and C# programming.

Open Visual Studio 2008 and create a new solution, as explained earlier. Write the following code, which will dynamically create a meeting invite item, inside the ThisAddIn.cs file:

private void ThisAddIn_Startup(object sender, System.EventArgs e)
// Outlook PacktMeetingItem object to compose new meeting request
Outlook.AppointmentItem PacktMeetingItem = (Outlook.
PacktMeetingItem.MeetingStatus = Microsoft.Office.
// Set the subject for the meeting
PacktMeetingItem.Subject = "Changes in book content";
// Update the body information of the meeting
PacktMeetingItem.Body = "Work on the changes and update";
// Start Expiry Time of the meeting
PacktMeetingItem.Start = new DateTime(2008, 9, 28, 9, 0, 0);
// Set the recipient information
Outlook.Recipient PacktRecipient = PacktMeetingItem.Recipients.
Add("Radhika Rajagopalan");
PacktRecipient.Type = (int)Outlook.OlMeetingRecipientType.
// If parameter is set to false compose MeetingItem won't display
// To send the composed PacktMeetingItem

As we can see in the following screenshot, a Meeting tab is created successfully after executing this program.

VSTO 3.0 for Office 2007 Programming

An Outlook meeting is one of the many types of Appointments in Outlook. Meetings are internally linked with the Outlook calendar. A meeting request can be created using only the AppointmentItem object. To create and set the meeting invitation by using the AppointmentItem, you must set the MeetingStatus property to olMeeting.


Please enter your comment!
Please enter your name here