Quantcast
Channel: NetOffice - MS Office in .NET
Viewing all articles
Browse latest Browse all 1741

New Post: Handle Outlook new contact event

$
0
0
void IDTExtensibility2.OnStartupComplete(ref Array custom)
{
  Outlook._NameSpace outlookNs = _outlookApplication.Session;
  Outlook.MAPIFolder contactFolder = outlookNs.GetDefaultFolder(Outlook.Enums.OlDefaultFolders.olFolderContacts);
  var contacts = (Outlook.Items)contactFolder.Items;

  //Add is a method//contactFolder.Items.Add += new NetOffice.OutlookApi.Items_ItemAddEventHandler(OnAddContact);//ItemAddEvent is an event
  contacts.ItemAddEvent += new Outlook.Items_ItemAddEventHandler(OnAddContact);
}

void OnAddContact(NetOffice.COMObject item)
{
  var contact = (Outlook.ContactItem)item;
  MessageBox.Show(contact.FullName);
}

Notes

  • I suppose you initialize _outlookApplication variable in IDTExtensibility2.OnConnection method.
  • This code tracks new contacts only in default contacts folder. It is possible to have multiple (including nested) contact folders.

Viewing all articles
Browse latest Browse all 1741

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>