Naresh Bojja

June 26, 2008

VSTO – Importing addresses from Database to OUTLOOK

Filed under: Others, VSTO — Naresh Bojja @ 7:09 pm

I am a fresh bee at VSTO concepts. I have been working on this since 4days.Out of my curiosity; today I tried a small example which will be useful in our office environment. Our Company has intranet portal which contains all the details about the employee. Every one updates their profile now and then in that portal i.e. Phone numbers, Designation, Manager Information, and Department. I want to be updated with the outlook contacts information. And also we need not bother about adding new employee Email information to our contacts. If any employee leaves the company, his/her Email id is no longer required. This is automatically taken care off by this application.

In this application we have two features. One is to IMPORT all the contacts. This is useful for the first time. And the second feature is for synchronizing with Outlook. If any information changes for an employee it will updates that info. If a new contact is found, then it will add that contact to outlook contacts while synchronizing.

Coding:

Step1:
Create a new VSTO project. Here I select OutLook 2007 addin.
Creating VSTO OutLook addin

Step2:
After creating the project I am creating a new connection to my database. Now add an .xsd file to my project. And drag the required table from your database to .xsd file.
Creating DBConnection and .xsd file 

Step3:
If you see your ThisAddIn.cs file, it has two basic methods.
ThisAddIn.cs file methods
Startup function is called when your application is opened and Shutdown is called when your application is closing.

What ever we want to write here comes into ThisAddIn_Startup(object sender, System.EventArgs e).
If you see the above picture I am calling in two methods in Startup method. When ever application is starting I am removing my menubar and adding it again.

Step4:
Removing menu bar.
Code to remove menubar item
Here I am getting my popupmenu item from the currently active window. If it is not null then I am removing it.

Step5:
Now I am adding the menu item. First I am adding a CommandBarPopup. In this popup menu ,I add two CommandBarButtons.
This picture shows how to add CommandBarPopup.
Creating menu item

This picture shows how to add CommandBarButton and also how to apply layout and button click event to this button.
Creating menu item

Step6:
Here I am writing code for Import button click event. When this button is clicked I get the data from database and loops through all the outlook contacts. If it is found I delete it and add it again.
Code to import contacts

Step7:
In this step I am writing code for synchronizing the outlook contacts with DB details. Every thing is same as above step except, if the contact is found I am updating it with the DB details.

Step8:
Press F5. If you see your output..
Final Output
Final OutPut

Top Sync My Addresses is the CommandbarPop up. The below two are the CommandBarButtons.
Click on these buttons and see the contacts for output.

Here I am attaching the zipped code Download file (Open the link in IE). For any more clarifications please go through it.
Note: please change the downloaded file extension from .jpg to .zip.

13 Comments »

  1. Your zip file doesnt seem to be their….. anychance of a copy to chris at logics dot co dot uk.

    Thanks

    Comment by Chris Bond — July 7, 2008 @ 7:39 pm | Reply

  2. Ignore that was firefox3 – worked fine in ie – thanks!

    Comment by Chris Bond — July 7, 2008 @ 7:40 pm | Reply

  3. The zip file is not there, is there another link to this?

    Comment by Anthony Brown — September 8, 2008 @ 4:29 pm | Reply

  4. I have uploaded the zip file as .jpg file extension..after downloading it rename it to .zip extension.

    Comment by Naresh Bojja — September 8, 2008 @ 5:18 pm | Reply

  5. Hi, There is no one file for download, when i click on the download then it opens in new window and just display the static link.

    Comment by Jigisha — September 9, 2008 @ 12:35 pm | Reply

  6. I want your application zip file.The zip file is not there.is there any another link or site?
    please help me.i want urgent very

    Comment by Swapna Nandamuri — October 16, 2008 @ 7:56 pm | Reply

  7. Hi,

    How can I use Office 2003(Outlook 2003) with same code.

    Comment by John — February 18, 2009 @ 3:54 pm | Reply

    • I too dint worked with Outlook 2003. Let me try with 2003 version…

      thanks,
      naresh

      Comment by Naresh Bojja — March 17, 2009 @ 5:15 am | Reply

  8. Hiii this is a Great help!!!!!!
    I just need to know can we set the connection string in config file and access it from there.

    Comment by Amit — April 13, 2009 @ 3:50 pm | Reply

  9. Did anybody managed to let it work on Office 2003 meanwhile?
    I would love to add it into outlook 2003

    Comment by chris — May 18, 2009 @ 9:41 am | Reply

  10. Hey, nice tutorial!
    Any news yet for the outlook 2003 version?

    Would be greatly appreciated!

    Greetings

    Comment by Effix — September 11, 2009 @ 7:16 am | Reply

  11. I have one problem. I created a project following your instructions and when press F5 my Outlook runs but without new buttons.

    Comment by Mersudin — September 25, 2009 @ 7:54 am | Reply


RSS feed for comments on this post. TrackBack URI

Leave a comment

Blog at WordPress.com.