Programmatically creating Outlook appointments

Outlook Reference

Found myself needing to learn the basic of using the Microsoft Office API to programmatically creating appointments in Outlook.  The event will be initiated from SharePoint 2010, for various reasons I was unable to use the standard Outlook – SharePoint integration.

In this example I’ll demonstrate the basics of creating an Outlook Appointment…

First step is to add a reference into Visual Studio, Reference: Microsoft.Office.Interop.Outlook.

Once the reference is added you need to create a new Outlook Application, and then instantiate the object type you require, in this example…an Outlook appointment item.

Microsoft.Office.Interop.Outlook.Application outlookApp = new Microsoft.Office.Interop.Outlook.Application();

Microsoft.Office.Interop.Outlook.AppointmentItem appointmentItem =(Microsoft.Office.Interop.Outlook.AppointmentItem)outlookApp.
CreateItem(Microsoft.Office.Interop.
Outlook.OlItemType.olAppointmentItem);

As you’ve added the reference you get all the goodness of the intelliSense, obviously makes everything a lot easier.

Specify the Start and End date / time

appointmentItem.Start = DateTime.Now;
appointmentItem.End = DateTime.Now.AddHours(1);

Reminder settings

appointmentItem.ReminderSet = true;
appointmentItem.ReminderMinutesBeforeStart = 60;

Subject, location, and saving

appointmentItem.Subject = "Be Somewhere";
appointmentItem.Location = "Location 1";
appointmentItem.Body = "blah blah blah";
appointmentItem.Save();

Instead of calling ‘Save’ the appointment can be forwarded as a VCal attachment

protected void sendAsVcal(Microsoft.Office.Interop.Outlook.AppointmentItem appointmentItem)
{
Microsoft.Office.Interop.Outlook.MailItem mailItem = appointmentItem.ForwardAsVcal();
mailItem.SenderEmailAddress = "sysadmin@corp.net"
mailItem.To = "me@me.com";
mailItem.Send();
}

I initially built this as a console app to test the functionality, but can easily be moved to a standard web application project. Code above tested on Outlook 2007 / 2010.

Advertisements

3 thoughts on “Programmatically creating Outlook appointments

  1. Hi Team, I wanted to send event confirmation to user in form of outllok appointmnt and my code is in ASP.Classic, windows server 2000 and outlook is not installed.
    when i execute below code my webpage hangs up..
    Sub SendMeetingRequest()
    Dim objOL ‘As Outlook.Application
    Dim objAppt ‘As Outlook.AppointmentItem
    Const olAppointmentItem = 1
    Const olMeeting = 1
    Set objOL = CreateObject(“Outlook.Application”)
    Set objAppt = objOL.CreateItem(olAppointmentItem)
    With objAppt .Subject = “My Test Appointment”
    .Start = Now + 1
    .End = DateAdd(“h”, 1, .Start) ‘ make it a meeting request
    .MeetingStatus = olMeeting
    .RequiredAttendees = “someone@somewhere.dom”
    .Send
    End With
    Set objAppt = Nothing
    Set objOL = Nothing
    End Sub

    Is that because outllok not installed in my server? if yes then please let me know other solution

    Please help

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s