Partager via


Saving Contacts to Active Directory

Topic Last Modified: 2006-06-30

The Iperson.DataSource property returns the attached IDataSource interface. The IDataSource interface exposes the following four methods that save contacts to the Active Directory® directory service:

After you bind the contact to a data source, you can call the IDataSource.Save method to save changes to the bound data source. You can call the IDataSource.SaveTo method to bind to, and save data to, an existing item specified by a URL. To bind to, and save data to, a new item at a specified URL, you can call the IDataSource.SaveToContainer method. The IDataSource.SaveToObject method allows you to save data to another object at run time.

The LDAP binding string contains prefixes and distinguishing names that specify the position of the contact in the Active Directory hierarchy. Use the following prefixes: CN for common names, DC for domains, and O or OU for organizations. CN specifies the common name of the object and the classification of the object, such as users. Use as many DCs as necessary for each qualification in the domain name, including a DC for sub-domains.

Example

The following example shows how to create a contact and save it to Active Directory. The LDAP binding string contains the first and last names of the user, the classification of the user, and the domain of the server. The IDataSource.SaveTo method uses the LDAP binding string to save the contact to Active Directory.

Example

Visual Basic

'Declare variables
Dim iPer As New CDO.Person
Dim strLDAP As String

With iPer
'Set first and last names and company name
.FirstName = "Max"
.LastName = "Benson"
.Company = "Coho Winery"
'Indicate that this is a contact
.Fields("objectClass").Value = "contact"
'Save changes made to properties
.Fields.Update
End With

'Setup the LDAP string 
strLDAP = "LDAP://servername/cn=Max Benson, cn=users, dc=domain, dc=com"

'Save the contact to Active Directory
iPer.DataSource.SaveTo strURL

See Also

Other Resources

IDataSource Interface