'Find Outlook AppointmentItem for ContactItem
I am creating ContactItem from code using Microsoft.Office.Interop.Outlook. This works absolutely fine. If I assign a the property Birthday, an corresponding AppointmentItem is created automatically. This is also fine.
But now when I delete the ContactItem, the AppointmentItem stays. This is obviously not what I was going for.
localContactToDelete.Delete();
Is there a way to retrieve the associated AppointmentItem in order to delete it manually?
I read that it should be possible (see below), however I do not find the propoerties or whatever.
Solution 1:[1]
Thanks to Dmitry's tip for using OutlookSpy to identify the NameSchema of the needed property I came up with the following code. It's definitely not ready, but at least works for the moment. Any suggestions welcome.
Microsoft.Office.Interop.Outlook.Application outlookObject = new Microsoft.Office.Interop.Outlook.Application();
MAPIFolder contactFolder = outlookObject.Session.GetDefaultFolder(OlDefaultFolders.olFolderContacts);
Items contacts = contactFolder.Items;
Then comes the stuff selecting the contact, e.g. a foreach.
ContactItem contact;
PropertyAccessor pa = contact.PropertyAccessor;
Byte[] ba = pa.GetProperty("http://schemas.microsoft.com/mapi/id/{00062004-0000-0000-C000-000000000046}/804D0102");
string birthdayAppointmentItemID = BitConverter.ToString(ba).Replace("-", string.Empty);
NameSpace ns = outlookObject.GetNamespace("MAPI");
AppointmentItem birthdayAppointmentItem = ns.GetItemFromID(birthdayAppointmentItemID);
Solution 2:[2]
Take a look at a contact with the birthday/anniversary properties set using OutlookSpy (I am its author - click IMessage) - the entry id of the birthday appointment is stored in a named property with the DASL name of http://schemas.microsoft.com/mapi/id/{00062004-0000-0000-C000-000000000046}/804D0102. For the anniversary, use http://schemas.microsoft.com/mapi/id/{00062004-0000-0000-C000-000000000046}/804E0102.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | |
| Solution 2 | Dmitry Streblechenko |
