【问题标题】:Find Outlook AppointmentItem for ContactItem为 ContactItem 查找 Outlook AppointmentItem
【发布时间】:2014-07-17 14:07:41
【问题描述】:

我正在使用Microsoft.Office.Interop.Outlook 从代码中创建ContactItem。这绝对没问题。如果我分配属性Birthday,则会自动创建相应的AppointmentItem。这也很好。

但是现在当我删除 ContactItem 时,AppointmentItem 仍然存在。这显然不是我想要的。

localContactToDelete.Delete();

有没有办法检索关联的AppointmentItem 以便手动删除它?

我读到这应该是可能的(见下文),但是我没有找到属性或其他任何东西。

http://social.msdn.microsoft.com/Forums/office/en-US/6b481f74-8422-46d4-90a9-a5860dcb98b5/to-avoid-automatic-birthday-calendar-event-creation-when-creating-contact?forum=outlookdev

【问题讨论】:

    标签: c# outlook office-interop outlook-2010


    【解决方案1】:

    “我没有找到属性或其他什么”?你在哪里看的?查看使用OutlookSpy 设置生日/周年纪念属性的联系人(单击IMessage)- 生日约会的条目ID 存储在DASL 名称为http://schemas.microsoft.com/mapi/id/{00062004-0000-0000-C000-000000000046}/804D0102 的命名属性中。纪念日,请使用http://schemas.microsoft.com/mapi/id/{00062004-0000-0000-C000-000000000046}/804E0102

    【讨论】:

    • 谢谢!这给了我正确的线索!很酷,我不知道 OutlookSpy,我只是使用 Visual Studio 的调试控制台。我会把我的代码贴出来供大家使用,虽然效率还差得很远。
    【解决方案2】:

    感谢 Dmitry 使用 OutlookSpy 识别所需属性的 NameSchema 的提示,我想出了以下代码。它肯定还没有准备好,但至少目前有效。欢迎提出任何建议。

    Microsoft.Office.Interop.Outlook.Application outlookObject = new Microsoft.Office.Interop.Outlook.Application();
    
    MAPIFolder contactFolder = outlookObject.Session.GetDefaultFolder(OlDefaultFolders.olFolderContacts);
    Items contacts = contactFolder.Items;
    

    然后是选择联系人的内容,例如一个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);
    

    【讨论】:

    • 不要遍历所有约会 - 如果您知道条目 ID,只需调用 Namespace.GetItemFromId。
    • 好点,感谢您的评论。我相应地更新了我的答案。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-01-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-01-15
    • 1970-01-01
    相关资源
    最近更新 更多