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



The information in this article applies to:

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

This article was previously published under Q310555

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

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

    By default, Class1.cs is created.
  3. Add a reference to the Microsoft CDO for Exchange 2000 Library. To do this, follow these steps:
    1. On the Project menu, click Add Reference.
    2. On the COM tab, locate Microsoft CDO for Exchange 2000 Library, and then click Select.
    3. 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.
  4. Follow the same steps to add a reference to the Microsoft ActiveX Data Objects 2.5 Library.
  5. 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 = "http://ExchServer/Exchange/UserAlias/calendar";
    
    			ADODB.Connection oCn = new ADODB.Connection();
    			oCn.Provider = "exoledb.datasource";
    
    			oCn.Open(sURL, "", "", 0);  
    			if(oCn.State == 1)
    			{
    				Console.WriteLine("Good Connection");
    			}
    			else
    			{
    				Console.WriteLine("Bad Connection");
    			}			
    						
    			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("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 App in C#";
    			oApp.TextBody = "Hello...";
    
    			// Add Recurring
    			// Every Thursday starting Today and run 3 times
    			CDO.IRecurrencePatterns iRPatters = oApp.RecurrencePatterns;
    			CDO.IRecurrencePattern iRPatter = 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 Exceptions
    			CDO.IExceptions iExceps = oApp.Exceptions;
    			CDO.IException iExcep;
    
    			// 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");
    
    			
    			oApp.DataSource.SaveToContainer(sURL, null, 
    				ADODB.ConnectModeEnum.adModeReadWrite, 
    				ADODB.RecordCreateOptionsEnum.adCreateNonCollection, 
    				ADODB.RecordOpenOptionsEnum.adOpenSource, 
    				"", "");
    
    			oCn.Close();
    
    			oApp = null;
    			oCn = null;
    			oFields = null;
    			}
    			catch (Exception e)
    			{
    				Console.WriteLine("{0} Exception caught.", e);
    			}			
    		}
            }
    }
    					
  6. Modify the code where you see TODO.
  7. Press the F5 key to build and run the program.
  8. Verify that the specified appointments are created.

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