After last night's mossig meeting and my Outlook/VSTO presentation someone asked me about the following scenario:
"I want to capture the fact that a user changes an email address in the Outlook contacts list and call into a custom Web Service to update my LOB-system recording that change." For those that have used the Outlook object model before that is probably not a difficult task, for those new to Outlook and tempted by VSTO to give Office Integration a go it may not be so obvious so I decided to write a little bit of demo-code in C# to show how to setup the event handler, I'll leave the actual call to a Web Service or updating a database using .net classes up to the student as an exercise ;-). Start by creating a new Outlook Addin project, open ThisAddIn.cs and add the code below.
using Outlook = Microsoft.Office.Interop.Outlook;
using Office = Microsoft.Office.Core;
public partial class ThisAddIn
Outlook.Items items; // This on is important, keep the reference at the addin level, a local var in the startup method will get garbage collected and the events will stop firing.
private void ThisAddIn_Startup(object sender, System.EventArgs e)
ns = this.Application.GetNamespace("MAPI");
contactfolder = ns.GetDefaultFolder
items = contactfolder.Items;
private void ItemChanged( object item )
contact = (Outlook.ContactItem)item;
// This is were you do your thing......
The same is available for ItemAdd, for delete events you would have to hookup an ItemAdd to the DeletedItems folder.