How to use the CDOEX Library to create a recurring meeting that has exceptions in Visual Basic .NET (314367)



The information in this article applies to:

  • Microsoft Visual Basic .NET (2002)
  • Microsoft Exchange 2000 Server
  • Collaboration Data Objects for Exchange 2000
  • ActiveX Data Objects (ADO) 2.5

This article was previously published under Q314367

SUMMARY

This article describes how to use the Collaboration Data Objects (CDO) for Exchange 2000 (CDOEX) Library to create a recurring meeting that has exceptions in Microsoft Visual Basic .NET.

MORE INFORMATION

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.
  1. Start Microsoft Visual Studio .NET.
  2. On the File menu, point to New, and then click Project.
  3. In the Visual Basic Projects types list, click Console Application.

    By default, the Module1.vb file is created.
  4. Add a reference to the CDOEX Library. To do so, follow these steps:
    1. On the Project menu, click Add Reference.
    2. Click the COM tab, locate Microsoft CDO for Exchange 2000 Library, and then click Select.
    3. In the Add References dialog box, click OK.
    4. If you are prompted to generate wrappers for the libraries that you selected, click Yes.
  5. 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.
  6. 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
    					
  7. Search for the TODO text string in the code, and then modify the code for your environment.
  8. Press the F5 key to build and to run the program.
  9. Make sure that the meeting was created.

Modification Type:MinorLast Reviewed:8/25/2005
Keywords:kbXML kbHOWTOmaster KB314367 kbAudDeveloper