Microsoft KB Archive/310555

= How to use Microsoft Collaboration Data Objects for Exchange 2000 Library to create appointments with exceptions in Microsoft Visual C# .NET =

Article ID: 310555

Article Last Modified on 11/29/2007

-

APPLIES TO


 * Microsoft Exchange Server 2003 Enterprise Edition
 * Microsoft Exchange Server 2003 Standard Edition
 * Microsoft Exchange 2000 Server Standard Edition
 * Collaboration Data Objects for Exchange 2000
 * Microsoft Visual C# .NET 2002 Standard Edition
 * Microsoft ActiveX Data Objects 2.5

-



This article was previously published under Q310555



Caution ADO and ADO MD have not been fully tested in a Microsoft .NET Framework environment. They may cause intermittent issues, especially in service-based applications or in multithreaded applications. The techniques that are discussed in this article should only be used as a temporary measure during migration to ADO.NET. You should only use these techniques after you have conducted complete testing to make sure that there are no compatibility issues. Any issues that are caused by using ADO or ADO MD in this manner are unsupported. For more information, see the following article in the Microsoft Knowledge Base:

840667 You receive unexpected errors when using ADO and ADO MD in a .NET Framework application





SUMMARY
This article describes how to use Microsoft Collaboration Data Objects (CDO) for Exchange 2000 Library to create appointments with exceptions in Microsoft Visual C# .NET.

Note To function correctly, you must run the code discussed in this article on Microsoft Exchange Server.



MORE INFORMATION
 Start Microsoft Visual Studio .NET. On the File menu, click New, and then click Project. Select Console Application from the Visual C# .NET Projects types.

By default, Class1.cs is created. Add a reference to the Microsoft CDO for Exchange 2000 Library. To do this, follow these steps:  On the Project menu, click Add Reference. On the COM tab, locate Microsoft CDO for Exchange 2000 Library, and then click Select. Click OK in the Add References dialog box to accept your selections. If you receive a prompt to generate wrappers for the libraries you selected, click Yes.</li></ol> </li> Follow the same steps to add a reference to the Microsoft ActiveX Data Objects 2.5 Library.</li>  In the Code window, replace all the code with the following code: using System;

namespace Samples {   class Class1 {       static void Main(string[] args) {           try {           CDO.Appointment oApp = new CDO.Appointment;

// TODO: Replace with your folder URL string sURL = &quot;http://ExchServer/Exchange/UserAlias/calendar&quot;;

ADODB.Connection oCn = new ADODB.Connection; oCn.Provider = &quot;exoledb.datasource&quot;;

oCn.Open(sURL, &quot;&quot;, &quot;&quot;, 0); if(oCn.State == 1) {               Console.WriteLine(&quot;Good Connection&quot;); }           else {               Console.WriteLine(&quot;Bad Connection&quot;); }                      CDO.Configuration iConfg = new CDO.Configuration; ADODB.Fields oFields;

oFields = iConfg.Fields; oFields[CDO.CdoCalendar.cdoTimeZoneIDURN].Value = CDO.CdoTimeZoneId.cdoPacific; oFields.Update;

oApp.Configuration = iConfg; oApp.StartTime = Convert.ToDateTime(&quot;10/11/2001 10:00:00 AM&quot;); oApp.EndTime = Convert.ToDateTime(&quot;10/11/2001 11:00:00 AM&quot;); oApp.Location = &quot;My Cube&quot;; oApp.Subject = &quot;Test Create App in C#&quot;; oApp.TextBody = &quot;Hello...&quot;;

// Add Recurring // Every Thursday starting Today and run 3 times CDO.IRecurrencePatterns iRPatters = oApp.RecurrencePatterns; CDO.IRecurrencePattern iRPatter = iRPatters.Add(&quot;Add&quot;); iRPatter.Frequency = CDO.CdoFrequency.cdoWeekly; iRPatter.Interval = 1;   // 1 hour from 10 to 11 iRPatter.DaysOfWeek.Add(4); // every Thursday iRPatter.Instances = 3;

// Specify Exceptions CDO.IExceptions iExceps = oApp.Exceptions; CDO.IException iExcep;

// Delete iExcep = oApp.Exceptions.Add(&quot;DELETE&quot;); iExcep.RecurrenceID = Convert.ToDateTime(&quot;10/11/2001 10:00:00 AM&quot;);

// Modify iExcep = oApp.Exceptions.Add(&quot;MODIFY&quot;); iExcep.RecurrenceID = Convert.ToDateTime(&quot;10/18/2001 10:00:00 AM&quot;); iExcep.StartTime = Convert.ToDateTime(&quot;10/17/2001 10:00:00 AM&quot;); iExcep.EndTime = Convert.ToDateTime(&quot;10/17/2001 1:00:00 pM&quot;);

oApp.DataSource.SaveToContainer(sURL, null,                ADODB.ConnectModeEnum.adModeReadWrite,                 ADODB.RecordCreateOptionsEnum.adCreateNonCollection,                 ADODB.RecordOpenOptionsEnum.adOpenSource,                 &quot;&quot;, &quot;&quot;);

oCn.Close;

oApp = null; oCn = null; oFields = null; }           catch (Exception e)            { Console.WriteLine(&quot;{0} Exception caught.&quot;, e); }                  }        } }                    </li> Modify the code where you see TODO.</li> Press the F5 key to build and run the program.</li> Verify that the specified appointments are created.</li></ol>

Additional query words: CDOEX ADO EXOLEDB

Keywords: kbhowtomaster KB310555

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.