Microsoft KB Archive/314378

= How to enumerate all fields of an object by using the CDOEX library and the ExOLEDB provider in Visual Basic .NET =

Article ID: 314378

Article Last Modified on 11/29/2007

-

APPLIES TO


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

-



This article was previously published under Q314378



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





For a Microsoft Visual C# .NET version of this article, see 310203.



INTRODUCTION
This article describes how to use Microsoft Collaboration Data Objects (CDO) for the Microsoft Exchange 2000 Server Library (CDOEX) to enumerate all fields of an object in Microsoft Visual Basic .NET.

Note To make sure that the code works correctly, you must run the code on an Exchange Server.



Requirements
This article assumes that you are familiar with the following topics:
 * Microsoft Exchange OLE DB (ExOLEDB) provider
 * Programming with ActiveX Data Objects Library

The following list outlines the recommended hardware, software, network infrastructure, and service packs that you need:
 * Microsoft Visual Studio .NET
 * Microsoft Exchange 2000 Server

To create a sample that lists all fields of an object, follow these steps:  Start Visual Studio .NET. On the File menu, click New, and then click Project. Under Visual Basic Projects types, click Console Application.

By default, Module1.vb 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.</li> On the COM tab, click Microsoft CDO for Exchange 2000 Library, and then click Select.</li> In the Add References dialog box, click OK to accept your selections.</li> Click Yes if you receive a message to generate wrappers for the libraries that you selected.</li></ol> </li> Repeat the previous steps to add a reference to the Microsoft ActiveX Data Objects 2.5 Library.</li>  Replace all the code in the code window with the following code: Module Module1

Sub Main 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

' TODO: Replace with your object URL (folder or item). Dim sFdUrl As String sFdUrl = &quot;http://<ExchServer>/Exchange/<UserAlias>/Inbox&quot;

oCn.Provider = &quot;exoledb.datasource&quot; oCn.Open(sFdUrl, &quot;&quot;, &quot;&quot;, -1)

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.adFailIfNotExists, _         ADODB.RecordOpenOptionsEnum.adOpenSource, _         &quot;&quot;, &quot;&quot;)

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

' List all the fields. oFields = oRc.Fields Dim i As Integer For i = 0 To oFields.Count - 1 oField = oFields.Item(i) Console.WriteLine(&quot;{0} : {1}&quot;, oField.Name, oField.Value) Next

oRc.Close oCn.Close

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

End Module </li> Modify the line of code that begins with TODO.</li> Press F5 to build and to run the program.</li> Verify that the fields of the specified object are enumerated.</li></ol>

<div class="references_section">