Specifying Exceptions to Recurring Appointments and Meetings
Topic Last Modified: 2006-06-12
Exceptions are specific appointments that are added, modified, or deleted from the pattern of a recurring appointment or meeting. For example, if a recurring pattern generates a meeting that falls on a holiday, you can define an exception to that one instance of the recurring pattern.
Collaboration Data Objects (CDO) uses IRecurrencePattern objects and IException objects to define exceptions to recurring appointments and meetings. The following table shows how each object can be used.
Object | Type | Action |
---|---|---|
IRecurrencePattern |
Add |
Adds a set of instances. |
IRecurrencePattern |
Delete |
Deletes a set of instances. |
IException |
Add |
Adds a single instance. |
IException |
Delete |
Deletes a single instance. |
IException |
Modify |
Changes the properties of one or more instances (equivalent to a Microsoft® Outlook® exception). |
To specify an exception to a recurring appointment or a meeting
- Create the recurring appointment or meeting.
- Create an Exception object by using the Add method on the Exceptions collection of the Appointment object, or create a RecurrencePattern object by using the Add method on the RecurrencePatterns collection.
- Set the properties of the Exception or RecurrencePattern object to specify appointment instances that are being added, deleted, or modified.
This topic contains Microsoft Visual Basic®, Microsoft C#, and Visual Basic .NET code examples.
Example
Visual Basic
The following example creates a recurring meeting and reschedules the 7th instance to start 2 hours later.
' Reference to Microsoft ActiveX Data Objects 2.5 Library
' Reference to Microsoft CDO for Exchange 2000 Library
' Note: It is recommended that all input parameters be validated when they are
' first obtained from the user or user interface.
Function CreateApptWithException(iMbx As IMailbox) As CDO.Appointment
Dim iAppt As New Appointment
Dim Config As New Configuration
Dim RRULE As IRecurrencePattern
Dim iCalMsg As CalendarMessage
Dim EXDATE As IException
Dim RDATE As IException
Dim Conn As New ADODB.Connection
Conn.Provider = "ExOLEDB.DataSource"
With iAppt
'Set the first appointment properties
.StartTime = Now
.EndTime = DateAdd("n", 60, Now) ' 60 minute appointment starting now
.Subject = "Read the Exchange SDK Docs."
.Location = "My Office"
'Create the RecurrencePattern object
Set RRULE = .RecurrencePatterns.Add("Add")
'Define the recurrence pattern
RRULE.Frequency = cdoDaily 'use a daily pattern
RRULE.Interval = 1 'every day
RRULE.PatternEndDate = DateAdd("d", 7, Now) 'the last appointment, 7 days from now at this time.
'Delete an appointment instance
Set EXDATE = .Exceptions.Add("Delete")
'The ID is the start time of the instance being deleted
EXDATE.RecurrenceID = DateAdd("d", 7, Now) ' Except the 7th day...reschedule.
'Add an appointment instance
Set RDATE = .Exceptions.Add("Add")
' Start 2 hours later on the seventh day
RDATE.StartTime = DateAdd("n", -60, DateAdd("d", 7, Now))
RDATE.EndTime = DateAdd("d", 7, Now)
'Save the appointment to the organizer's calendar
Conn.Open iMbx.BaseFolder
.DataSource.SaveToContainer iMbx.Calendar, Conn
' Clean up.
Conn.Close
Set Conn = Nothing
End With
Set CreateApptWithException = iAppt
End Function
C#
The following example creates a recurring meeting and reschedules the 7th instance to start 2 hours later.
// Reference to Microsoft ActiveX Data Objects 2.5 Library
// Reference to Microsoft CDO for Exchange 2000 Library
// Note: It is recommended that all input parameters be validated when they are
// first obtained from the user or user interface.
static CDO.Appointment CreateApptWithException(CDO.IMailbox iMbx)
{
try
{
// Variables.
CDO.Appointment iAppt = new CDO.Appointment();
CDO.Configuration Config = new CDO.Configuration();
CDO.IRecurrencePattern RRULE;
CDO.IException EXDATE;
CDO.IException RDATE;
ADODB.Connection Conn = new ADODB.Connection();
Conn.Provider = "ExOLEDB.DataSource";
// Set the first appointment properties.
iAppt.StartTime = DateTime.Now;
// Set the end time for 60 minutes from now.
iAppt.EndTime = DateTime.Now.Add(TimeSpan.FromMinutes(60));
iAppt.Subject = "Read the Exchange SDK Docs.";
iAppt.Location = "My Office";
// Create the RecurrencePattern object.
RRULE = iAppt.RecurrencePatterns.Add("Add");
// Define the recurrence pattern. Use the daily pattern.
RRULE.Frequency = CDO.CdoFrequency.cdoDaily;
// Every day.
RRULE.Interval = 1;
// The last appointment, 7 days from now at this time.
RRULE.PatternEndDate = DateTime.Now.Add(TimeSpan.FromDays(7));
// Delete an appointment instance.
EXDATE = iAppt.Exceptions.Add("Delete");
// Reschedule the 7th day. The ID is the start time of
// the instance being deleted.
EXDATE.RecurrenceID = DateTime.Now.Add(TimeSpan.FromDays(7));
// Add an appointment instance.
RDATE = iAppt.Exceptions.Add("Add");
// Start 2 hours later on the seventh day.
RDATE.StartTime = DateTime.Now.Add(TimeSpan.FromDays(7)-TimeSpan.FromMinutes(60));
RDATE.EndTime = DateTime.Now.Add(TimeSpan.FromDays(7));
// Save the appointment to the organizer's calendar.
Conn.Open(iMbx.BaseFolder, "", "", -1);
iAppt.DataSource.SaveToContainer(iMbx.Calendar, Conn,
ADODB.ConnectModeEnum.adModeReadWrite,
ADODB.RecordCreateOptionsEnum.adCreateNonCollection,
ADODB.RecordOpenOptionsEnum.adOpenSource, "", "");
Console.WriteLine("Appointment created.");
// Close the connection.
Conn.Close();
return iAppt;
}
catch (Exception err)
{
Console.WriteLine(err.ToString());
return null;
}
}
Visual Basic .NET
The following example creates a recurring meeting and reschedules the 7th instance to start 2 hours later.
' Reference to Microsoft ActiveX Data Objects 2.5 Library
' Reference to Microsoft CDO for Exchange 2000 Library
' Note: It is recommended that all input parameters be validated when they are
' first obtained from the user or user interface.
Function CreateApptWithException(ByVal iMbx As CDO.IMailbox) As CDO.Appointment
Try
' Variables.
Dim iAppt As New CDO.Appointment()
Dim Config As New CDO.Configuration()
Dim RRULE As CDO.IRecurrencePattern
Dim EXDATE As CDO.IException
Dim RDATE As CDO.IException
Dim Conn As New ADODB.Connection()
Conn.Provider = "ExOLEDB.DataSource"
With iAppt
' Set the first appointment properties.
.StartTime = Now
' Set the end time for 60 minutes from now.
.EndTime = DateAdd(DateInterval.Minute, 60, Now)
.Subject = "Read the Exchange SDK Docs."
.Location = "My Office"
' Create the RecurrencePattern object.
RRULE = .RecurrencePatterns.Add("Add")
' Define the recurrence pattern. Use the daily pattern.
RRULE.Frequency = CDO.CdoFrequency.cdoDaily
' Every day.
RRULE.Interval = 1
' The last appointment, 7 days from now at this time.
RRULE.PatternEndDate = DateAdd(DateInterval.Day, 7, Now)
' Delete an appointment instance.
EXDATE = .Exceptions.Add("Delete")
' Reschedule the 7th day. The ID is the start time of
' the instance being deleted.
EXDATE.RecurrenceID = DateAdd(DateInterval.Day, 7, Now)
' Add an appointment instance.
RDATE = .Exceptions.Add("Add")
' Start 2 hours later on the seventh day.
RDATE.StartTime = DateAdd(DateInterval.Minute, -60, DateAdd(DateInterval.Day, 7, Now))
RDATE.EndTime = DateAdd(DateInterval.Day, 7, Now)
' Save the appointment to the organizer's calendar.
Conn.Open(iMbx.BaseFolder)
.DataSource.SaveToContainer(iMbx.Calendar, Conn)
End With
Console.WriteLine("Appointment created.")
' Close the connection.
Conn.Close()
CreateApptWithException = iAppt
Catch err As Exception
Console.WriteLine(err.ToString())
CreateApptWithException = Nothing
End Try
End Function