Introduction
This article describes how to add or update Calendar/Tasks Appointment items using the CDO Appointment object.
Using the Code
Open the Exchange Server connection:
Dim ADOExchangeConn as new ADODB.Connection
Dim MailBoxUrl as string = "http://100.100.100.10/Exchange/test/Calendar/213.eml"
ADOExchangeConn.Provider = "ExOLEDB.DataSource"
ADOExchangeConn.Open(MailBoxURL, ExchangeUserName, ExchangePassword, 0)
The MailBoxURL
can be described as follows:
- 100.100.100.10 - Exchange IP Address
- Exchange - Server Name
- test - User Name
- Calendar - Folder
- 231.eml - eml filename
Define the CDO Appointment object:
Dim objCDOApp as CDO.Appointment
To add subject, we need to set:
CDO.CdoDAV.cdoContentClass.Equals("urn:content-classes:appointment")
objCDOApp.Fields.Item(http://schemas.microsoft.com/exchange/outlookmessageclass).Value =
"IPM.Appointment"
Then, set subject as follows:
objCDOApp.Subject = sDisplayName
objCDOApp.Priority = 0
objCDOApp.AllDayEvent = True
objCDOApp.BusyStatus = "FREE"
objCDOApp.Duration = 86400
objCDOApp.Fields("urn:schemas:calendar:reminderoffset").Value = 64800
If event is a One Day event, then StartTime
should be like "Date 00:00:00 AM", otherwise Calendar will show the same event (appointment) on two successive dates. Also, converting date to GMT is necessary:
Dim dtTemp1 As Date = DatePart(DateInterval.Month, strStartTime) & "/" & _
DatePart(DateInterval.Day, strStartTime) & "/" & _
DatePart(DateInterval.Year, strStartTime) &
" 00:00:00 AM"
Dim iGmtDiff As Double =
DateDiff(DateInterval.Minute, System.DateTime.UtcNow(), System.DateTime.Now())
Dim dtTemp2 As Date = DateAdd(DateInterval.Minute, -iGmtDiff, dtTemp1)
objCDOApp.StartTime = dtTemp2.Date
dtTemp2 = DateAdd(DateInterval.Day, 1, dtTemp2)
objCDOApp.EndTime = dtTemp2.Date
objCDOApp.Contact = "H"
objCDOApp.TextBody = "There is meeting today with H"
// This line is required to update objCDOApp.Fields("ReminderOffSet").Value = 600
objCDOApp.Fields.Update()
Use the "var" button to wrap Variable or class names in <code>
tags like this:
objCDOApp.DataSource.SaveTo(MailboxUrl, , ADODB.ConnectModeEnum.adModeReadWrite,
ADODB.RecordCreateOptionsEnum.adCreateOverwrite,
ADODB.RecordOpenOptionsEnum.adOpenSource, exchangeusername, exchangepwd)
History
- 30th November, 2007: Initial post