I searched and searched the net some more, but could not find code to add and appointment, delete a appointment and list appointments in a user’s Outlook Calendar. I found bits of code here and there, checked the CDO help file and then finally managed to put some code together. The best part is…it works!
I have below detailed instructions on how to manipulate appointments via ASP. Take a look at the prerequisites below, and the source code.
Prerequisites:
- IIS 6 / 7
- MS Office 2003 or MS Office 2007
- MS Exchange must NOT be installed on the operating system running the ASP files
Notes:
If you have MS Office 2007 installed, the CDO object DOES NOT come with it. You have to download the CDO install package (version 1.2.1) from here http://www.microsoft.com/downloadS/details.aspx?familyid=2714320D-C997-4DE1-986F-24F081725D36&displaylang=en, and then install it. You need to set up the permissions on IIS too. To get it working for me, I have:
Basic authentication enabled with our domains administrator account setup here
Windows authentication enabled
Basic authentication enabled
Source Code:
Add An Appointment
<%
Set CDOSession = Server.CreateObject(”MAPI.Session”)
CDOSession.Logon “”, “”, False, True, 0, True, “EXCHANGEMAILSERVER1″ & vbLf & “jdoe”
Set ApptItem = CDOSession.GetDefaultFolder(CdoDefaultFolderCalendar).Messages.Add
‘** RH ** create appointment item
ApptItem.StartTime = “10/10/2008 9:00:00 AM”
ApptItem.EndTime = “10/10/2008 11:00:00 AM”
ApptItem.AllDayEvent = False
ApptItem.ReminderMinutesBeforeStart = 30
ApptItem.ReminderSet = True
ApptItem.Location = “Meeting Room 5″
ApptItem.Text = “Description text goes here”
ApptItem.Subject = “Meeting subject goes here”
ApptItem.Recipients.Add “jdoe@mail.com”
ApptItem.Recipients.Resolve
ApptItem.MeetingStatus = 1
‘** RH ** add the meeting
ApptItem.Update True, True
‘** RH ** below code to send a meeting request to recipient, un-comment if meeting request email is needed
‘ApptItem.Send
Set ApptItem = Nothing
CDOSession.Logoff
%>
Appointment Created!
Delete An Appointment
<%
Set CDOSession = Server.CreateObject(”MAPI.Session”)
CDOSession.Logon “”, “”, False, True, 0, True, “EXCHANGEMAILSERVER1″ & vbLf & “jdoe”
Set oFolder = CDOSession.GetDefaultFolder(CdoDefaultFolderCalendar)
Set oMessages = oFolder.Messages
Set objAppointmentFilter = oMessages.Filter
‘** RH ** with filter, for some reason the end datetime MUST be swapped with the start datetime to work, added the hex and decimal values
‘to filter the start dates and times. For some reason on some systems either the hex works or the decimal works or both. No idea why?
‘** RH ** Start Date (dd/mm/yy time)
‘objAppointmentFilter.Fields.Add &H00600040, “11/10/08″ ‘HEX
objAppointmentFilter.Fields.Add 6291520, “11/10/08″ ‘DECIMAL
‘** RH ** End Date (dd/mm/yy time)
‘objAppointmentFilter.Fields.Add &H00610040, “9/10/08″ ‘HEX
objAppointmentFilter.Fields.Add 6357056, “9/10/08″ ‘DECIMAL
Set oAppointment = oMessages.GetFirst
Do While Not oAppointment Is Nothing
‘** RH ** delete appointment on subject, can use others to delete on
If oAppointment.Subject = “Meeting subject goes here” Then
oAppointment.Delete
Exit Do
End If
Set oAppointment = oMessages.GetNext
Loop
Set oFolder = Nothing
Set oMessages = Nothing
Set objAppointmentFilter = Nothing
Set oAppointment = Nothing
CDOSession.Logoff
Set CDOSession = Nothing
%>
Appointment Deleted!
List Appointments
<%
Set CDOSession = Server.CreateObject(”MAPI.Session”)
CDOSession.Logon “”, “”, False, True, 0, True, “EXCHANGEMAILSERVER1″ & vbLf & “jdoe”
Set oFolder = CDOSession.GetDefaultFolder(CdoDefaultFolderCalendar)
Set oMessages = oFolder.Messages
Set objAppointmentFilter = oMessages.Filter
‘** RH ** with filter, for some reason the end datetime MUST be swapped with the start datetime to work
‘** RH ** Start Date (dd/mm/yy time)
objAppointmentFilter.Fields.Add &H00600040, “10/10/08 11:59:59 PM”
‘** RH ** End Date (dd/mm/yy time)
objAppointmentFilter.Fields.Add &H00610040, “10/10/08 00:00:01 AM”
Set oAppointment = oMessages.GetFirst
Do While Not oAppointment Is Nothing
Response.write “Appointment: ” & oAppointment.Subject & “<br>”
Response.write “Start Time: ” & oAppointment.StartTime & “<br>”
Response.write “End Time: ” & oAppointment.EndTime & “<br>”
Response.write “Location: ” & oAppointment.Location & “<br>”
Response.write “Description: ” & oAppointment.Text & “<br>”
Set oAppointment = oMessages.GetNext
Loop
CDOSession.Logoff
%>
And thats it!
Play around with the permissions in IIS if you having problems getting the code to work. I had to try many different IIS permissions settings to get it to run, so that should be your starting point if you run into any problems