Click here to Skip to main content
15,883,938 members
Articles / Programming Languages / C#
Tip/Trick

Global Address Book for Outlook using C# with VSTO

Rate me:
Please Sign up or sign in to vote.
5.00/5 (5 votes)
4 Jul 2016MIT2 min read 27.5K   886   7   5
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.

Image 1

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. 

C#
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.

C#
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
<?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.

C#
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, along with any associated source code and files, is licensed under The MIT License


Written By
Hong Kong Hong Kong
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
QuestionSource does not go Pin
Member WilliD4-Jul-16 12:07
professionalMember WilliD4-Jul-16 12:07 
AnswerRe: Source does not go Pin
terence.cplau4-Jul-16 18:05
terence.cplau4-Jul-16 18:05 
SuggestionSize of the source file Pin
Wendelius30-Jun-16 23:15
mentorWendelius30-Jun-16 23:15 
GeneralRe: Size of the source file Pin
Slacker0071-Jul-16 0:22
professionalSlacker0071-Jul-16 0:22 
GeneralRe: Size of the source file Pin
terence.cplau1-Jul-16 16:32
terence.cplau1-Jul-16 16:32 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.