Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles / desktop / WinForms

Adding Updating Calendar,Tasks Appointment using CDO Object

2.71/5 (5 votes)
30 Nov 2007CPOL 2  
How to Add or Update Exchange Calendar/Tasks files using CDOAppointment object

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:

VB.NET
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:

VB.NET
Dim objCDOApp as CDO.Appointment

To add subject, we need to set:

VB.NET
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:

VB.NET
objCDOApp.Subject = sDisplayName
objCDOApp.Priority = 0
objCDOApp.AllDayEvent = True
objCDOApp.BusyStatus = "FREE"
objCDOApp.Duration = 86400
objCDOApp.Fields("urn:schemas:calendar:reminderoffset").Value = 64800
'''we can also Set objCDOApp.Fields("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:

VB.NET
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:

VB.NET
 objCDOApp.DataSource.SaveTo(MailboxUrl, , ADODB.ConnectModeEnum.adModeReadWrite, 
    ADODB.RecordCreateOptionsEnum.adCreateOverwrite, 
    ADODB.RecordOpenOptionsEnum.adOpenSource,  exchangeusername, exchangepwd)
'''  'SaveTo' function adds new eml also updates if the eml exists.

History

  • 30th November, 2007: Initial post

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)