Click here to Skip to main content
Click here to Skip to main content
Go to top

Working with vCards using the MS CDO for Exchange Library

, 1 Feb 2006
Rate this:
Please Sign up or sign in to vote.
vCard is a popular format developed to exchange business information. It was developed to easily share your contacts with other people. In this article, I will explain how to get personal infromation from a vCard, edit it, and save the changes in a file.

Introduction

vCard is a popular format developed to exchange business information. It was developed to easily share your contacts with other people using email clients, internet, or event portable devices and cell phones. A vCard file includes text information about name, home and business addresses, phone numbers, and other things. It can also include your photo or company’s logo.

I am working on a web project where users can upload vCards into a system to export personal information. I searched for any information about working with vCards, in MSDN, and found a link to the CDO.Person object in the Microsoft CDO For Exchange 2000 Library. This library doesn’t present until you install Exchange Server. But I Googled and found codex.dll separately here. I registered it using the regsvr32 utility and added it to my Visual Studio project.

If you take a look at the IPerson Interface description, you can find such properties like FirstName, LastName, Company etc. There is also a method GetVCardStrem which returns the ADO Stream object containing the vCard stream information.

For example, to create a CDO.Person object from a vCard file, use the following code:

CDO.Person person = new CDO.Person();
ADODB.Stream s = person.GetVCardStream();
s.LoadFromFile(this.vCardFileName);
s.Flush();

Now, you can access all the CDO.Person properties to retrieve the personal information:

txtFirstName.Text = person.FirstName;
txtLastName.Text = person.LastName;
txtEmail.Text = person.Email;
txtHomePhone.Text = person.HomePhone;
txtCellPhone.Text = person.MobilePhone;

Also, you can store a CDO.Person object into a vCard file using the SaveToFile method of ADODB.Stream:

ADODB.Stream s = person.GetVCardStream();
s.SaveToFile(@“c:\vCard.vcf”, 
    ADODB.SaveOptionsEnum.adSaveCreateOverWrite);

The first discomfort of this method is the necessity to register COM on a remote server when you are using this approach for web applications. The second problem is you can not work with included images in a vCard. But this is the easiest way to get the main information about a person's contact information from his vCard when you have the Microsoft CDO For Exchange 2000 Library installed.

I created a Windows application in Visual Studio 2005 using C#, with the example code where you can open a sample vCard file, preview data, change it, and then save it in a file. Before running the project, check whether the Microsoft CDO For Exchange library is registered. If not, download it from here and register cdoex.dll with the regsvr32 utility.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

Share

About the Author

Alexander Kleshchevnikov
Web Developer
Ukraine Ukraine
Alexander is freelance web developer with 4 years experience. He has skills in ASP.NET/MS SQL Server, PHP/MySQL, Ruby On Rails, XHTML, CSS. You can contact with me by seigo.ua@gmail.com. Also check my homepage at www.klalex.com.

Comments and Discussions

 
Generaldoesn't have Person Pinmembermsn_issue5-Jun-10 9:53 
GeneralRe: doesn't have Person PinmemberAsthana Pratik18-Jul-10 19:46 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Mobile
Web01 | 2.8.140916.1 | Last Updated 1 Feb 2006
Article Copyright 2006 by Alexander Kleshchevnikov
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid