Import Outlook Contacts using the SharePoint client-side API

A few weeks back a developer asked me, “How can I allow users to select contacts from their address book on a web page?”  After drilling into his initial question, I learned that he really wanted to add the same “Import Contacts” functionality that SharePoint natively provides for Contact lists to his own custom ASP.NET Web App.  While researching his potential solutions I discovered that this functionality is contained in a COM component called the Spread Sheet Launcher Control that’s provided as part of SharePoint’s client-side API.  This component is contained within a COM library named MSOSVABW.DLL, which is located in the Microsoft Office install directory by default. 

I created an example ASP.NET application that uses this component to import selected contacts from an Outlook address book as XML data to the server.  My example is based on a simple code example from the Sharepoint SDK documentation.   Basically I have a simple ASP.NET WebForm with some client-side script.  When the user clicks a “Select Contacts” button in my page (screenshot here), the client-side event handler instantiates the Spread Sheet Launcher Control (MsSvAbw.AddrBookWrapper) and displays the standard contact list picker dialog window to the user.  From this window, the user can select one or more contacts from any of their registered Address Books.  By clicking on the “Advanced” button, the user can also elect to create a new contact in their address book or specify criteria and search for a contact.  Here’s an example of the contact list picker with my sample address book:

When the user clicks the OK button, they will be receive the following security warning from Outlook where they are asked to grant access to the application (in this case our web page) that is trying to access their address book.

The script in my ASP.NET WebForm enumerates through the selected address book entries and builds an XML formatted string containing the data for the contacts.  After the XML formatted string is constructed, it is stuffed in a hidden HTML input element, which is posted back to the server.  My simple WebForm just take the data that is posted in the hidden HTML input element and displays it in a text box, as you can see in the following screenshot.  However, at this point, you could easily use the XML contact data within your application, store it in a database, etc.

Since this example relies on the COM component to be installed on the local user’s machine, one immediate concern that comes to mind is compatibility with other versions of Office.  I accessed my simple ASP.NET Web Application from a machine running Windows XP and it worked fine.  The only difference I noticed between Office XP and 2003 was the look and behavior for the Address Book list window.   Here’s a screenshot of the Address Book list window from my Office XP machine.

I haven’t included the source code in this blog entry for the sake of space, but you can download my code example from here.

Here are a few links to the product documentation that might also be helpful:

This posting is provided “AS IS” with no warranties, and confers no rights.