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



The information in this article applies to:

  • Collaboration Data Objects for Exchange 2000
  • Microsoft Visual C# .NET (2002)
  • ActiveX Data Objects (ADO) 2.5
  • Microsoft Exchange 2000 Server SP1
  • Microsoft Visual C# 2005

This article was previously published under Q310203

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

  1. Start Microsoft Visual Studio .NET or Microsoft Visual Studio 2005.
  2. On the File menu, click New, and then click Project.
  3. 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.
  4. Add a reference to the MDO for Exchange 2000 Library and the Microsoft ActiveX Data 2.5 Library. To do so, follow these steps:
    1. On the Project menu, click Add Reference.
    2. Click the COM tab, click Microsoft CDO for Exchange 2000 Library in the Component Name, and then click Select.
    3. 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.
    4. Click OK. If you are prompted to generate wrappers for the libraries that you selected, click Yes.
  5. 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 = "http://ExchServer/exchange/UserAlias/Inbox";
    
    			
    			oCn.Provider = "exoledb.datasource";
    			oCn.Open(sFdUrl, "", "", -1);  
    
    			if(oCn.State == 1)
    			{
    				Console.WriteLine("Good Connection");
    			}
    			else
    			{
    				Console.WriteLine("Bad Connection");
    			}
    
    			oRc.Open(sFdUrl, oCn, 
    				ADODB.ConnectModeEnum.adModeReadWrite, 
    				ADODB.RecordCreateOptionsEnum.adFailIfNotExists,
    				ADODB.RecordOpenOptionsEnum.adOpenSource,
    				"", "");
    
    			
    			oFields = oRc.Fields;
    
    			for(int i = 0; i < oFields.Count; i++)
    			{
    				oField = oFields[i];
    				Console.WriteLine("{0} : {1}", oField.Name, oField.Value);
    			}
    
    			oRc.Close();
    			oCn.Close();
    
    			oCn = null;
    			oRc = null;
    			oFields = null;
    			oField = null;
    			}
    			catch (Exception e)
    			{
    				Console.WriteLine("{0} Exception caught.", e);
    			}			
    		}
            }
    }
    					

  6. Modify code where you see the TODO comments.
  7. Press F5 to build and to run the program.
back to the top

REFERENCES

For more information, visit the following Microsoft Developer Network (MSDN) Web site: back to the top

Modification Type:MinorLast Reviewed:10/4/2006
Keywords:kbHOWTOmaster KB310203 kbAudDeveloper