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:
- Spread Sheet Launcher Control documentation
- “Importing Contacts with the Spreadsheet Launcher Control”
This posting is provided “AS IS” with no warranties, and confers no rights.
Comments
- Anonymous
June 06, 2004
What is the point in importing contacts client-side, if it is imporrible to sunchronize changes from Outlook 2003 back to the sharepoint server? - Anonymous
June 06, 2004
This functionality wouldn’t necessarily be used to allow the user to “synchronize” their contacts to the Sharepoint server. Rather, I have seen several scenarios where a web-based application (mostly outside of Sharepoint) could provide the ability for the user to pick contacts from their address book, rather than requiring the user to manually enter email addresses or contact information.
Imagine a simple approval process/workflow where the initiator for the process needs to assign people to the workflow. Or a web-based application that needs to send an email out to a list of people. Microsoft Live Meeting (http://www.livemeeting.com/) is an example of a web-based application that fits this scenario. Today if I need to schedule an online meeting from the Live Meeting site, I have to manually enter the email address for each person I want to invite or pick a person from an address book that Live Meeting stores (and I maintain). Why not provide users the ability to pick the people from their local address book or their Exchange Global Address List using this approach? - Anonymous
July 13, 2004
How do I do the revese?
Add a contact from the website to the outlook?
/mathias - Anonymous
August 07, 2004
The comment has been removed