Notice: This website is an unofficial Microsoft Knowledge Base (hereinafter KB) archive and is intended to provide a reliable access to deleted content from Microsoft KB. All KB articles are owned by Microsoft Corporation. Read full disclaimer for more details.

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


View products that this article applies to.

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 (http://support.microsoft.com/kb/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 (http://support.microsoft.com/kb/310200/ ) .
For a Microsoft Visual C# .NET version of this article, see 310200 (http://support.microsoft.com/kb/310200/ ) .

↑ Back to the top


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.

↑ Back to the top


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:
  1. Start Microsoft Visual Studio .NET.
  2. On the File menu, point to New, and then click Project.
  3. In the Visual Basic Projects list, click Console Application.

    By default, Module1.vb is created.
  4. Add a reference to the CDOEX Library. To do so, follow these steps:
    1. On the Project menu, click Add Reference.
    2. Click the COM tab, locate Microsoft CDO for Exchange 2000 Library, and then click Select.
    3. In the Add References dialog box, click OK.
    4. 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
  5. 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.
  6. 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 = "file://./backofficestorage/<domain>/MBX/<Mailbox>/Contacts/"
    
            Dim oFields As ADODB.Fields
            oFields = oItem.Fields
    
            oFields.Item("DAV:contentclass").Value = "urn:content-classes:person"
            oFields.Item("http://schemas.microsoft.com/exchange/outlookmessageclass").Value = "IPM.Contact"
            oFields.Item("urn:schemas:contacts:cn").Value = "David Jones"
            oFields.Item("urn:schemas:contacts:nickname").Value = "Dave"
            oFields.Item("urn:schemas:contacts:title").Value = "Engineer"
            oFields.Item("urn:schemas:contacts:department").Value = "DSW Messaging"
            oFields.Item("urn:schemas:contacts:email1").Value = "someone@example.com"
            oFields.Item("urn:schemas:contacts:fileas").Value = "Dave Jones"
    
            ' update
            oFields.Update()
    
            oItem.DataSource.SaveToContainer(sURL, , _
             ADODB.ConnectModeEnum.adModeReadWrite, _
             ADODB.RecordCreateOptionsEnum.adCreateNonCollection, _
             ADODB.RecordOpenOptionsEnum.adOpenSource, _
             "", "")
    
            oItem = Nothing
            oFields = Nothing
        End Sub
    
    End Module
  7. Search for the TODO text string in the code, and then modify the code for your environment.
  8. Press F5 to build and to run the program.
  9. Make sure that the contact was created.

↑ Back to the top


References

For information about the urn:content-classes:person content class, visit the following Microsoft Web site: 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
287534� PRB: ExOLEDB provider cannot access or create items remotely

↑ Back to the top


Keywords: KB314363, kbhowto

↑ Back to the top

Article Info
Article ID : 314363
Revision : 4
Created on : 11/29/2007
Published on : 11/29/2007
Exists online : False
Views : 598