Microsoft KB Archive/314363

= How to create a contact by using an Item object in Visual Basic .NET =

Article ID: 314363

Article Last Modified on 11/29/2007

-

APPLIES TO


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

-



This article was previously published under Q314363



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 310200.



SUMMARY
This article describes how to use the Microsoft Collaboration Data Objects (CDO) for Exchange 2000 (CDOEX) Library to create a contact by using an Item object in Microsoft Visual Basic .NET.



MORE INFORMATION
Note CDOEX is only directly supported on the computer that is running Microsoft Exchange 2000 Server where the mailbox is stored. The following code sample assumes that you are working on the local server.

To create a contact by using an Item object in Visual Basic .NET, follow these steps:  Start Microsoft Visual Studio .NET. On the File menu, point to New, and then click Project. In the Visual Basic Projects 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.</li> 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.

Note In Microsoft .NET Framework applications, CDOEX is supported only through a COM interop. For additional information, click the following article number to view the article in the Microsoft Knowledge Base:

813349 Support policy for Microsoft Exchange APIs with .NET Framework applications

</li></ol> </li> To add a reference to the Microsoft ActiveX Data Objects 2.5 Library, repeat step 4.

Note In step 4b, substitute Microsoft ActiveX Data Objects 2.5 Library for Microsoft CDO for Exchange 2000 Library.</li>  In the code window, replace the code with the following code: Module Module1

Sub Main Dim oItem As CDO.Item = New CDO.Item

' TODO: Replace with your folder URL sURL = &quot;file://./backofficestorage/ /MBX/<Mailbox>/Contacts/&quot;

Dim oFields As ADODB.Fields oFields = oItem.Fields

oFields.Item(&quot;DAV:contentclass&quot;).Value = &quot;urn:content-classes:person&quot; oFields.Item(&quot;http://schemas.microsoft.com/exchange/outlookmessageclass&quot;).Value = &quot;IPM.Contact&quot; oFields.Item(&quot;urn:schemas:contacts:cn&quot;).Value = &quot;David Jones&quot; oFields.Item(&quot;urn:schemas:contacts:nickname&quot;).Value = &quot;Dave&quot; oFields.Item(&quot;urn:schemas:contacts:title&quot;).Value = &quot;Engineer&quot; oFields.Item(&quot;urn:schemas:contacts:department&quot;).Value = &quot;DSW Messaging&quot; oFields.Item(&quot;urn:schemas:contacts:email1&quot;).Value = &quot;someone@example.com&quot; oFields.Item(&quot;urn:schemas:contacts:fileas&quot;).Value = &quot;Dave Jones&quot;

' update oFields.Update

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

oItem = Nothing oFields = Nothing End Sub

End Module </li> Search for the TODO text string 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 contact was created.</li></ol>

<div class="references_section">