To use the CDOEX Library to create a recurring meeting in Visual Basic .NET, follow these steps.
Note To work correctly, run the sample code on a computer that is running Microsoft
Exchange 2000 Server.
- Start Microsoft Visual Studio .NET.
- On the
File menu, point to New, and then click
Project.
- In the Visual Basic Projects types list, click Console Application.
By
default, the Module1.vb file is created. - Add a reference to the CDOEX
Library. To do so, follow these steps:
- On the Project menu, click Add
Reference.
- Click the COM tab, locate
Microsoft CDO for Exchange 2000 Library, and then click
Select.
- In the Add
References dialog box, click OK.
- If you are
prompted to generate wrappers for the libraries that you selected, click
Yes.
- Repeat step 4 to add a reference to the Microsoft
ActiveX Data Objects 2.5 Library.
Note In step 4b, substitute Microsoft ActiveX Data Objects 2.5 Library for Microsoft CDO for Exchange 2000 Library. - In the code window, replace the code with the following:
Module Module1
Sub Main()
' TODO: Replace with your folder URL
Dim sURL As String
sURL = "http://<ExchServer>/Exchange/<UserAlias>/calendar"
Dim oCn As ADODB.Connection = New ADODB.Connection()
oCn.Provider = "exoledb.datasource"
oCn.Open(sURL, "", "", 0)
If oCn.State = 1 Then
Console.WriteLine("Good Connection")
Else
Console.WriteLine("Bad Connection")
Return
End If
Dim iConfg As CDO.Configuration = New CDO.Configuration()
Dim oFields As ADODB.Fields
oFields = iConfg.Fields
oFields.Item(CDO.CdoCalendar.cdoTimeZoneIDURN).Value = CDO.CdoTimeZoneId.cdoPacific
' TODO: Set Meeting Organizer
oFields.Item(CDO.CdoConfiguration.cdoSendEmailAddress).Value = "organizer@example.com"
oFields.Update()
Dim oApp As CDO.Appointment = New CDO.Appointment()
oApp.Configuration = iConfg
oApp.StartTime = Convert.ToDateTime("10/11/2001 10:00:00 AM")
oApp.EndTime = Convert.ToDateTime("10/11/2001 11:00:00 AM")
oApp.Location = "My Cube"
oApp.Subject = "Test: Create Meeting in VB.NET"
oApp.TextBody = "Hello..."
' Add recurring appointment
' Every Thursday starting today, and repeat 3 times.
Dim iRPatters As CDO.IRecurrencePatterns = oApp.RecurrencePatterns
Dim iRPatter As CDO.IRecurrencePattern = iRPatters.Add("Add")
iRPatter.Frequency = CDO.CdoFrequency.cdoWeekly
iRPatter.Interval = 1 ' 1 hour from 10 to 11
iRPatter.DaysOfWeek.Add(4) ' every Thursday
iRPatter.Instances = 3
' Specify the exceptions.
Dim iExceps As CDO.IExceptions = oApp.Exceptions
Dim iExcep As CDO.IException
' Delete
iExcep = oApp.Exceptions.Add("DELETE")
iExcep.RecurrenceID = Convert.ToDateTime("10/11/2001 10:00:00 AM")
' Modify
iExcep = oApp.Exceptions.Add("MODIFY")
iExcep.RecurrenceID = Convert.ToDateTime("10/18/2001 10:00:00 AM")
iExcep.StartTime = Convert.ToDateTime("10/17/2001 10:00:00 AM")
iExcep.EndTime = Convert.ToDateTime("10/17/2001 1:00:00 pM")
' Add thee attendees.
Dim iAtdees As CDO.IAttendees = oApp.Attendees
Dim iAtdee As CDO.IAttendee = iAtdees.Add("User1@dudomain.example.com") ' TODO:
'iAtdee.Address = "User1@dudomain.example.com" ' TODO:
Dim iCalMsg As CDO.ICalendarMessage = oApp.CreateRequest()
iCalMsg.Message.Send()
' Save to the folder
oApp.DataSource.SaveToContainer(sURL, , _
ADODB.ConnectModeEnum.adModeReadWrite, _
ADODB.RecordCreateOptionsEnum.adCreateNonCollection, _
ADODB.RecordOpenOptionsEnum.adOpenSource, _
"", "")
oCn.Close()
oApp = Nothing
oCn = Nothing
oFields = Nothing
End Sub
End Module
- Search for the TODO text string in the code, and then modify the code for your environment.
- Press the F5 key to build and to run the program.
- Make sure that the meeting was created.