Wednesday, May 6, 2009

Reading Outlook Contacts in VB.NET

In this article I am trying to read the Outlook contact into a Combo Box and selecting a contact I am displaying his/ her details in below Label controls, so lets start building example.

Create a Windows Forms Application and Add Label and Combo Box and change the lable text to Select Contact.

To use the Outlook object in our project we need include a dll from the add references, now add a reference and select "Microsoft.Office.Interop.Outlook" dll from the list.

After adding the dll, now we will import the name space for that use following import

To access Outlook we need to create a object for Outlook via its interface and to get current session we need a NameSpace object to create these object use following code

Imports

Now in the Form Load we will initialise the objects and fill the combo box with contact names, for that in the Form_Load use following code

FormLoad

Once we get the list of contacts in the Combo box use will select a Contact on selecting a contact we will display his or her details in the labels we put on the form for that we need to add following coding in the ComboBox_SelectedIndexChanged event, basically we are searching through all contacts and get the selected contact and display his or her details

We need to clear the object memory we used in the project in Form_Disposed event

ComboBoxSelect

Now we are ready with our code just build, run and test

Output

Tags: Reading Outlook Contacts using VB.NET

2 comments:

  1. This is great, I wished if you left the code as text, but thanks after all .

    ReplyDelete
  2. Thanks for sharing this...

    I want to get Manager Name of a contact. Can you help me please? Thanks a lot in advance.

    ReplyDelete