Microsoft KB Archive/314374

= How to use the CDOEX library and the ExOLEDB provider to create an Outlook contact in Visual Basic .NET =

Article ID: 314374

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 Q314374



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 Microsoft Exchange 2000 (CDOEX) library and the Exchange OLE DB provider (ExOLEDB) to create a Microsoft Outlook contact in Microsoft Visual Basic .NET.



MORE INFORMATION
To use the CDOEX library and the ExOLEDB provider to create an Outlook contact in Visual Basic .NET, follow these steps:  Start Microsoft Visual Studio .NET. On the File menu, point to New, and then click Project. Under Project Types, click Visual Basic Projects. Under Templates, click Console Application, and then click OK.

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. If you receive a prompt 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 all the code with the following.

Note You must run the following code sample on a computer that is running Microsoft Exchange 2000 Server for the code sample to run correctly. Module Module1

Sub Main ' TODO: Replace the URL with your folder URL. Dim sURL As String sURL = &quot;http://<ExchServer>/Exchange/<UserAlias>/Contacts&quot;

Dim oCn As ADODB.Connection = New ADODB.Connection oCn.Provider = &quot;exoledb.datasource&quot;

oCn.Open(sURL, &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

Dim oPerson As CDO.Person = New CDO.Person oPerson.Title = &quot;Engineer&quot; oPerson.FirstName = &quot;Joe&quot; oPerson.LastName = &quot;Healy&quot; oPerson.Company = &quot;Fabrikam, Inc.&quot; oPerson.Email = &quot;abc@fabrikam.com&quot; oPerson.FileAs = &quot;Joe Healy&quot;

oPerson.DataSource.SaveToContainer(sURL,, _        ADODB.ConnectModeEnum.adModeReadWrite, _         ADODB.RecordCreateOptionsEnum.adCreateNonCollection, _         ADODB.RecordOpenOptionsEnum.adOpenSource, _         &quot;&quot;, &quot;&quot;)

oCn.Close

oPerson = Nothing oCn = Nothing End Sub

End Module </li> Search for &quot;TO DO&quot; in the code, and then modify the code for your environment.</li> Press F5 to build and to run the program.</li> Verify that the contact has been created.</li></ol>

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

Keywords: kbhowto KB314374

-

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

© Microsoft Corporation. All rights reserved.