Microsoft KB Archive/310197

= How to create an Outlook Calendar folder by using Collaboration Data Objects for Exchange 2000 Library in Visual C# =

Article ID: 310197

Article Last Modified on 11/29/2007

-

APPLIES TO


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

-



This article was previously published under Q310197



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



IN THIS TASK

 * INTRODUCTION
 * Create the Outlook Calendar folder



INTRODUCTION
This article describes how to use Microsoft Collaboration Data Objects (CDO) for Microsoft Exchange 2000 Library to create a Microsoft Outlook Calendar folder in Microsoft Visual C#.

Note To work correctly, this code must be run on an Exchange server.

back to the top

Create the Outlook Calendar folder
To create an Outlook Calendar folder by using Visual Studio .NET, follow these steps:  Start Microsoft Visual Studio .NET or Microsoft Visual Studio 2005. On the File menu, click New, and then click Project. Under Project Types, click Visual C# Projects.

Note In Visual Studio 2005, click Visual C# under Project Types. Under Templates, double-click Console Application.

In Visual Studio .NET, Class1.cs is created by default. In Visual Studio 2005, Program.cs is created by default. Add a reference to the CDO for Exchange 2000 Library. To do this, follow these steps:  On the Project menu, click Add Reference.</li> 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.</li> In the Add References dialog box, click OK to accept your selection.

If you are prompted to generate wrappers for the libraries that you selected, click Yes.</li></ol> </li> Follow steps 5a through 5c 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 {               /*                 sType            Value MailItems       IPF.Note ContactItems    IPF.Contact AppointmentItems IPF.Appointment NoteItems       IPF.StickyNote TaskItems       IPF.Task JournalItems    IPF.Journal */

// Create a Calendar folder. String sType = &quot;IPF.Appointment&quot;;

ADODB.Connection oCn = new ADODB.Connection; ADODB.Record oRc = new ADODB.Record;

ADODB.Fields oFields; ADODB.Field oField;

string sFolderTypeProperty; sFolderTypeProperty = &quot;http://schemas.microsoft.com/exchange/outlookfolderclass&quot;;

// TODO: Replace the URL with your new folder URL. string sFdUrl = &quot;http://ExchServer/Exchange/UserAlias/Inbox/NewFolder&quot;;

oCn.Provider = &quot;exoledb.datasource&quot;;

oCn.Open(sFdUrl, &quot;&quot;, &quot;&quot;, 0); if(oCn.State == 1) {               Console.WriteLine(&quot;Good Connection&quot;); }           else {               Console.WriteLine(&quot;Bad Connection&quot;); }

oRc.Open(sFdUrl, oCn,                  ADODB.ConnectModeEnum.adModeReadWrite,                 ADODB.RecordCreateOptionsEnum.adCreateCollection,                 ADODB.RecordOpenOptionsEnum.adOpenSource,                 &quot;&quot;, &quot;&quot;);

// Get fields. oFields = oRc.Fields;

// The property has been set to a variable. oField = oFields[sFolderTypeProperty]; oField.Value = sType; oFields.Update; oRc.Close; oCn.Close;

oCn = null; oRc = null; oFields = null; oField = null; }           catch (Exception e)            { Console.WriteLine(&quot;{0} Exception caught.&quot;, e); }                  }        } }                    </li> Modify the code accordingly where you see the TODO comment.</li> Press F5 to build and to run the program.</li> Verify that the Outlook folder was created.</li></ol>

back to the top

Additional query words: Visual C# .NET CDOEX ADO EXOLEDB Outlook Folder

Keywords: kbmsg kbxml kbcode kbhowtomaster KB310197

-

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

© Microsoft Corporation. All rights reserved.