Microsoft KB Archive/310203

= How to list all fields of an object by using Collaboration Data Objects for Exchange 2000 Server Library in Visual C# =

Article ID: 310203

Article Last Modified on 11/29/2007

-

APPLIES TO


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

-



This article was previously published under Q310203



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
SUMMARY
 * Create the Sample to List All Fields of an Object

REFERENCES



SUMMARY
This article describes how to use Microsoft Collaboration Data Objects (CDO) for Exchange 2000 Server Library to list all of the fields of an object in Microsoft Visual C#.

back to the top

Create the Sample to List All Fields of an Object
 Start Microsoft Visual Studio .NET or Microsoft Visual Studio 2005. On the File menu, click New, and then click Project. Click Visual C# Projects, and then double-click Console Application from the Visual C# Projects types. By default, Class1.cs is created.

Note In Visual Studio 2005, click Visual C# under Project Types. In Visual Studio 2005, Program.cs is created by default. Add a reference to the MDO for Exchange 2000 Library and the Microsoft ActiveX Data 2.5 Library. To do so, follow these steps:  On the Project menu, click Add Reference. Click the COM tab, click Microsoft CDO for Exchange 2000 Library in the Component Name, and then click Select.</li> Click Microsoft ActiveX Data Objects 2.5 Library in the Component Name list, and then click Select.

Note In Visual Studio 2005, you do not have to click Select.</li> Click OK. If you are prompted to generate wrappers for the libraries that you selected, click Yes.</li></ol> </li>  In the Code window, replace the default code with the following code: using System;

namespace Samples {   class Class1 {       static void Main(string[] args) {           try {           ADODB.Connection oCn = new ADODB.Connection; ADODB.Record oRc= new ADODB.Record;

ADODB.Fields oFields; ADODB.Field oField;

// TODO: Replace with your folder URL 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) {               Console.WriteLine(&quot;Good Connection&quot;); }           else {               Console.WriteLine(&quot;Bad Connection&quot;); }

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

oFields = oRc.Fields;

for(int i = 0; i < oFields.Count; i++) {               oField = oFields[i]; Console.WriteLine(&quot;{0} : {1}&quot;, oField.Name, oField.Value); }

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 code where you see the TODO comments.</li> Press F5 to build and to run the program.</li></ol>

back to the top

<div class="references_section">