Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles
(untagged)

Global Address Book for Outlook using C# with VSTO

0.00/5 (No votes)
4 Jul 2016 1  
ContactSharing4OL is an Add-in for Outlook through file server shared contacts item of Outlook in Office area.

 

Introduction

ContactSharing4OL is an Add-in for Outlook through file server shared contacts item of Outlook in office area. It is a VSTO project developed in Visual Studio using C#.

Background

It is a simple tool to attach contacts data (file base) between Outlook and file server that made it a Global address book for Outlook. Once add-in is ready with file server configured, click button 'Global Contacts' will pop up the dialog box which will allow you to select recipients.

Use case and Assumptions

I assume you are able handle Outlook VSTO concept. If you are not, below part of "How Add-in Works" may hard to read.

The following part will explain add-in how working probably. Please check the details in sources.

How Add-in Works

Step 1

Using Visual Studio, create Outlook Add-in project name call "ContactSharing4OL" and then add new item of Ribbon (XML) name call "CSRibbon". We got two files under ContactSharing4OL project, one "CSRibbon.cs" an other "CSRibbon.xml"(due to the this xml file specific Outlook.Mail.Compose behavior, so I changed name "MailComposeInspectorRibbon.xml"). The XML is a custom ribbon UI layout file to control like button position, what function call, image in button. "CSRibbon.cs" containing codes.

Step 2

Please do not forget add below code of first block in "ThisAddin.cs". Must be higher than ThisAddIn_Startup block for override default Ribbon layout. 

protected override Microsoft.Office.Core.IRibbonExtensibility CreateRibbonExtensibilityObject()
{
    return new CSRibbon();
}

private void ThisAddIn_Startup(object sender, System.EventArgs e)
{

}

private void ThisAddIn_Shutdown(object sender, System.EventArgs e)
{

}

Step 3

Due to my purpose for mail compose, therefore I added below code in "CSRibbon.cs". Mean my code will be fired when Outlook handling email events.

public string GetCustomUI(string ribbonID)
{
    switch (ribbonID)
    {
        case "Microsoft.Outlook.Mail.Compose":
                    return GetResourceText("ContactSharing4OL.MailComposeInspectorRibbon.xml");
        default:
                    return null;         
    }
}

Code of ContactSharing4OL.MailComposeInspectorRibbon.xml. My custom button is added in default ribbon group "TabNewMailMessage" position before "GroupClipboard". So, button will position at top of left.

<?xml version="1.0" encoding="UTF-8"?>
<customUI onLoad="Ribbon_Load" xmlns="http://schemas.microsoft.com/office/2006/01/customui">
  <ribbon>
    <tabs>
      <tab idMso="TabNewMailMessage">
        <group id="group1" label="ContactSharing" insertBeforeMso="GroupClipboard">
          <button id="GlobalContactBtn" onAction="GlobalContactInspectorRibbonBtn_Click" 
           label="Global Contacts" size="large" getImage="GetGlobalImg"/>
        </group>
      </tab>
    </tabs>
  </ribbon>
</customUI>

Step 4

Loading data part I added in "ThisAddin_Startup.cs", here will loading data between Outlook and server everytime when Outlook launch.

private void ThisAddIn_Startup(object sender, System.EventArgs e)
{
    // ... call my synchronize function here to load data up
}

Step 5

Now we can startup my add-in ContactSharing4OL, lauch custom code during compose email. What about the data? I selected "Outlook Contact item", because it is easy handling by user, they can prepareing contacts on the Outlook and then drag and drop into file server. Also, easy edit, update and delete those item. Obviously this weakness point as well, because a contact item default size up to 256k. So, be careful high volume usage. 

Development prerequisites

  • Visual Studio 2010 Tools for Office Runtime
  • Microsoft .NET Framework 4.0
  • Visual Studio Community 2013 with update 4
  • Microsoft Office Developer Tools for Visual Studio 2013 - November 2014 update
  • Wix ToolSet v4

Points of Interest

Although Microsoft does not provide Address Book Provider API for C#, we can through other API functions to call what to do in Outlook. Here, I found the way to made this Global Address book, it is good for users to achieve Global Address book functionality without Exchange, Lotus Notes email system.

History

  • 1July2016: Article updated
  • 30th June, 2016: Initial release

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