Share via


How to: Programmatically create appointments

Applies to: yesVisual Studio noVisual Studio for Mac

Note

This article applies to Visual Studio 2017. If you're looking for the latest Visual Studio documentation, see Visual Studio documentation. We recommend upgrading to the latest version of Visual Studio. Download it here

This example creates an appointment and adds recipients to the appointment meeting request.

Applies to: The information in this topic applies to VSTO Add-in projects for Outlook. For more information, see Features available by Office application and project type.

Example

private void AddAppointment()
{
    try
    {
        Outlook.AppointmentItem newAppointment =
            (Outlook.AppointmentItem)
        this.Application.CreateItem(Outlook.OlItemType.olAppointmentItem);
        newAppointment.Start = DateTime.Now.AddHours(2);
        newAppointment.End = DateTime.Now.AddHours(3);
        newAppointment.Location = "ConferenceRoom #2345";
        newAppointment.Body =
            "We will discuss progress on the group project.";
        newAppointment.AllDayEvent = false;
        newAppointment.Subject = "Group Project";
        newAppointment.Recipients.Add("Roger Harui");
        Outlook.Recipients sentTo = newAppointment.Recipients;
        Outlook.Recipient sentInvite = null;
        sentInvite = sentTo.Add("Holly Holt");
        sentInvite.Type = (int)Outlook.OlMeetingRecipientType
            .olRequired;
        sentInvite = sentTo.Add("David Junca ");
        sentInvite.Type = (int)Outlook.OlMeetingRecipientType
            .olOptional;
        sentTo.ResolveAll();
        newAppointment.Save();
        newAppointment.Display(true);
    }
    catch (Exception ex)
    {
        MessageBox.Show("The following error occurred: " + ex.Message);
    }
}

See also