Notice: This website is an unofficial Microsoft Knowledge Base (hereinafter KB) archive and is intended to provide a reliable access to deleted content from Microsoft KB. All KB articles are owned by Microsoft Corporation. Read full disclaimer for more details.

How to create a new recurring meeting that has exceptions by using CDOEX in Visual C#


View products that this article applies to.

This article was previously published under Q310558
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 (http://support.microsoft.com/kb/840667/ ) You receive unexpected errors when using ADO and ADO MD in a .NET Framework application

↑ Back to the top


Introduction

This article describes how to use Microsoft Collaboration Data Objects (CDO) for Exchange 2000 Library to create a new recurring meeting that has exceptions in Microsoft Visual C#.

↑ Back to the top


More information

To create a new recurring meeting that has exceptions, follow these steps:
  1. Start Microsoft Visual Studio .NET or Microsoft Visual Studio 2005.
  2. On the File menu, click New, and then click Project.
  3. Under Visual C# Projects, select Console Application.

    Note In Visual Studio 2005, click Visual C# under Project Types.

    In Visual Studio .NET, Class1.cs is created by default. In Microsoft Visual Studio 2005, Program.cs is created by default.
  4. Add a reference to Microsoft CDO for Exchange 2000 Library (CDOEX). To do this, follow these steps:
    1. On the Project menu, click Add Reference.
    2. On the COM tab, click Microsoft CDO for Exchange 2000 Library, and then click Select.

      Note In Visual Studio 2005, you do not have to click Select.
    3. In the Add References dialog box, click OK to accept your selections.
    4. Click Yes if you receive a message to generate wrappers for the libraries that you selected.
    Note Collaboration Data Objects for Exchange 2000 Library is supported only when you use COM Interop.
  5. Follow the previous steps to add a reference to the Microsoft ActiveX Data Objects 2.5 Library.
  6. In the code window, replace all the code with the following sample code:
    using System;
    
    namespace Samples
    {
    	class Class1
    	{
    		static void Main(string[] args)
    		{
    			try 
    			{
    			CDO.Appointment oApp = new CDO.Appointment();
    
                                // TODO: Replace the Exchange server name and UserAlias with your own.
    			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("Connection Successful");
    			}
    			else
    			{
    				Console.WriteLine("Connection Failed");
    			}			
    						
    			CDO.Configuration iConfg = new CDO.Configuration();
    			ADODB.Fields oFields;
    
    
    			oFields = iConfg.Fields;
    			oFields[CDO.CdoCalendar.cdoTimeZoneIDURN].Value = CDO.CdoTimeZoneId.cdoPacific;
    
    			// Set Meeting Organizer.
    			// TODO: Change the e-mail address to your own e-mail address.
                                oFields[CDO.CdoConfiguration.cdoSendEmailAddress].Value = "someone@example.net";	
    			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 = "Office";
    			oApp.Subject = "Test: Create Meeting in C#";
    			oApp.TextBody = "Message body of test message...";
    
    			// Add the New Recurring Meeting
    			// every Thursday, starting today, and then run three 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");
    
    			// Add attendees.
                               // TODO: Change e-mail address to your own attendee.
    			CDO.IAttendees iAtdees = oApp.Attendees;
    			CDO.IAttendee iAtdee = iAtdees.Add("someone@example.net");
    
    			CDO.ICalendarMessage iCalMsg = (CDO.ICalendarMessage)oApp.CreateRequest();
    			iCalMsg.Message.Send();
    			
    
    			// Save to the Events Calendar.
    			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);
    			}			
    		}
            }
    }

  7. Modify the previous sample code where you see the lines that start with TODO.
  8. Press F5 to build and to run the program.
  9. Verify that the new recurring meeting has been created in the Calendar folder.

↑ Back to the top


References

For additional information about Exchange Server, visit the following Microsoft Developer Network (MSDN) Web site:For additional information about support policy for Microsoft Exchange APIs with .NET Framework applications, visit the following MSDN Web site:

↑ Back to the top


Keywords: KB310558, kbhowto, kbmsg, kbcode

↑ Back to the top

Article Info
Article ID : 310558
Revision : 6
Created on : 11/29/2007
Published on : 11/29/2007
Exists online : False
Views : 398