Microsoft KB Archive/314372

= How to use the CDOEX Library to create an Outlook Calendar folder in Visual Basic .NET =

Article ID: 314372

Article Last Modified on 11/29/2007

-

APPLIES TO


 * Microsoft ActiveX Data Objects 2.5
 * Collaboration Data Objects for Exchange 2000
 * Microsoft Exchange 2000 Server Standard Edition
 * Microsoft Visual Basic .NET 2002 Standard Edition

-



This article was previously published under Q314372



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 the Microsoft Collaboration Data Objects (CDO) for Exchange 2000 (CDOEX) Library to create a Microsoft Outlook Calendar folder in Microsoft Visual Basic .NET.



MORE INFORMATION
To create an Outlook Calendar folder in Visual Basic .NET, follow these steps.

Note You must run the following sample code on a computer that is running Microsoft Exchange 2000 Server.  Start Microsoft Visual Studio .NET. On the File menu, point to New, and then click Project. In the Visual Basic Projects types list, click Console Application.

By default, Module1.vb is created. Add a reference to the CDOEX Library. To do so, follow these steps:  On the Project menu, click Add Reference. Click the COM tab, locate Microsoft CDO for Exchange 2000 Library, and then click Select.</li> In the Add References dialog box, click OK.</li> If you are prompted to generate wrappers for the libraries that 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 the code with the following: Module Module1

Sub Main 'strFolderType   Name '       'MailItems        IPF.Note 'ContactItems    IPF.Contact 'AppointmentItems IPF.Appointment 'NoteItems       IPF.StickyNote 'TaskItems       IPF.Task 'JournalItems    IPF.Journal

Dim sType as String = &quot;IPF.Appointment&quot;

Dim oCn As ADODB.Connection = New ADODB.Connection Dim oRc As ADODB.Record = New ADODB.Record

Dim oFields As ADODB.Fields Dim oField As ADODB.Field

Dim sFolderTypeProperty As String sFolderTypeProperty = &quot;http://schemas.microsoft.com/exchange/outlookfolderclass&quot;

' TODO: Replace with your new folder URL Dim sFdUrl As 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 Then Console.WriteLine(&quot;Good Connection&quot;) Else Console.WriteLine(&quot;Bad Connection&quot;) Return End If

oRc.Open(sFdUrl, oCn, _        ADODB.ConnectModeEnum.adModeReadWrite, _         ADODB.RecordCreateOptionsEnum.adCreateCollection, _         ADODB.RecordOpenOptionsEnum.adOpenSource, _         &quot;&quot;, &quot;&quot;)  ' adOpenAsync is not supported

If oRc.State = ADODB.ObjectStateEnum.adStateOpen Then Console.WriteLine(&quot;Record Open Success&quot;) Else Console.WriteLine(&quot;Record Open Fails&quot;) Return End If

' Add Folder type oFields = oRc.Fields oField = oFields.Item(sFolderTypeProperty) oField.Value = sType

oFields.Update

oRc.Close oCn.Close

oCn = Nothing oRc = Nothing oFields = Nothing oField = Nothing End Sub

End Module </li> Search for TODO in the code, and then modify the code for your environment.</li> Press F5 to build and to run the program.</li> Make sure that the Outlook Calendar folder was created.</li></ol>

Additional query words: Visual Basic VB .NET CDOEX ADO exoledb Outlook Folder

Keywords: kbmsg kbhowtomaster KB314372

-

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

© Microsoft Corporation. All rights reserved.