Share via


Creating a Contact in the Exchange Store

Topic Last Modified: 2006-06-12

Creating a contact involves setting informational properties and saving the contact to the Exchange store.

Example

The following example creates a contact using the Collaboration Data Objects (CDO) Person object and saves it to the Exchange store.

Example

Visual Basic

Note

This example uses a file URL with the Exchange OLE DB (ExOLEDB) provider. The ExOLEDB provider also supports The HTTP: URL Scheme. Using The HTTP: URL Scheme allows both client and server applications to use a single URL scheme.

Sub CreateContactWebStore()

Dim oPerson As New CDO.Person
Dim strURL As String

oPerson.FirstName = "John"
oPerson.LastName = "Smith"
oPerson.HomeCity = "Redmond"
oPerson.HomeState = "Washington"
oPerson.Email = "jsmith@somewhere.example.com"
oPerson.Fields("objectClass").Value = "contact"
oPerson.Fields.Update

'URL to save the contact using Exchange OLE DB Provider
strURL = "file://./backofficestorage/fullyqualifieddomain.example.com/MBX/User1/Contacts/JohnSmith.eml"

'Save the contact to Exchange store
oPerson.DataSource.SaveTo strURL

End Sub

By default, the CDO person object creates a user. In the preceding code, the oPerson.Fields("objectClass").Value is set to type "contact" to create a contact.

The objectClass value is an array of variants, however the property can accept a single value. The value might be one of the following:

  oPerson.Fields("objectClass").Value = "contact"
  oPerson.Fields("objectClass").Value = Array("top", "person", _ "organizationalPerson", "contact")