Getting Appointments and Meetings from Folders in Exchange
Topic Last Modified: 2006-06-12
Microsoft® Exchange Server 2007 stores appointments and meetings in a user's calendar folder or in a public folder. By using a Collaboration Data Objects (CDO) Appointment object, you can open, view, and modify appointments and meetings in the Exchange store. Individual appointments and meetings are stored as single items in the Exchange store.
Recurring appointments are expanded into individual instances when the calendar folder is queried in the Exchange store. If you want to modify one or more instances of a recurring appointment, you can modify the master appointment. You can also modify the individual instances directly. The urn:schemas:calendar:instancetype field identifies master recurring appointments, recurring instances, single appointments, or exceptions to recurring appointments.
Although appointments and meetings can be stored in any Exchange folder, the Exchange store expands only recurring appointments and meetings that are stored in calendar folders.
To get an appointment from a calendar folder
- Open the calendar folder using a Microsoft ActiveX® Data Objects database (ADODB) record.
- Open an ADODB recordset containing the items in the calendar folder. Use a SELECT statement to include the item URL and the appointment date or other desired fields in the recordset. To expand recurring meetings, include a WHERE clause in the SELECT statement that specifies the range of dates where recurring instances are expanded.
- Enumerate the recordset, and then test each item's fields, as appropriate.
- For appointments that match your selection criteria, get the URL from the recordset, and then open the URL using a CDO Appointment object.
- Process the Appointment objects as needed.
The code in the following example lists appointments in the calendar folder of user12, on the Exchange 2007 named exsvr3 in the exchange.example.com domain. The code example selects appointments within a specific date range that have the subject "Department Meeting." It also prints the start and end times of the appointment, the subject, and the instance type.
Example
Visual Basic
Note
The following example uses a file URL with the Exchange OLE DB (ExOLEDB) provider. The ExOLEDB provider also supports The HTTP: URL Scheme. Using The HTTP: URL Scheme allows both client and server applications to use a single URL scheme.
Dim CalendarURL As String
Dim ItemURL As String
Dim Rs As New ADODB.Recordset
Dim Rec As New ADODB.Record
Dim iAppt As New Appointment
Dim dateStartDate As Date
Dim Subject As String
CalendarURL = "file://./backofficestorage/exchange.example.com/MBX/user12/calendar/"
'Open a recordset for the items in the calendar folder
Rec.Open CalendarURL
Set Rs.ActiveConnection = Rec.ActiveConnection
Rs.Source = "SELECT ""DAV:href"", " & _
" ""urn:schemas:httpmail:subject"", " & _
" ""urn:schemas:calendar:dtstart"", " & _
" ""urn:schemas:calendar:dtend"" " & _
"FROM scope('shallow traversal of """ & CalendarURL & """') " & _
"WHERE (""urn:schemas:calendar:dtstart"" >= CAST(""1999-08-01T08:00:00Z"" as 'dateTime')) " & _
"AND (""urn:schemas:calendar:dtend"" <= CAST(""1999-09-01T08:00:00Z"" as 'dateTime'))"
Rs.Open
'Enumerate the recordset, checking each item's subject
Rs.MoveFirst
Do Until Rs.EOF
'get the subject of each item
Subject = Rs.Fields(CdoHTTPMail.cdoSubject).Value
If Subject = "Department Meeting" Then
'open appointment
ItemURL = Rs.Fields(CdoDAV.cdoHref).Value
iAppt.DataSource.Open ItemURL
Debug.Print iAppt.StartTime & " - " & iAppt.EndTime
Debug.Print "Subject: " & iAppt.Subject
'print the type of appointment
Select Case iAppt.Fields(CdoCalendar.cdoInstanceType).Value
Case cdoSingle
Debug.Print "Single appointment"
Case cdoMaster
Debug.Print "Master recurring appointment"
Case cdoInstance
Debug.Print "Instance of recurring appointment"
Case cdoException
Debug.Print "Exception to recurring appointment"
Case Else
Debug.Print "Unknown"
End Select
End If
Rs.MoveNext
Loop