如何从ContextMenu获取Outlook约会

时间:2015-01-25 11:12:01

标签: c# .net outlook ms-office outlook-addin

我已将ContextMenuItem添加到ContextMenu for Outlook约会。

The menu item

问题在于我无法弄清楚如何获取Appointment对象。如果我得到一个IRibbonControl,它的Context属性应该包含Appointment,但它包含一个Selection。就我所见,我无法使用选择来预约。

enter image description here

此页面是我来自的地方:https://msdn.microsoft.com/en-us/library/office/ff863278%28v=office.14%29.aspx

任何人都知道如何获得预约?

2 个答案:

答案 0 :(得分:6)

Selection对象包含在图片上选择的AppointmentItem对象。例如:

                Object selObject = Selection[1];
                if (selObject is Outlook.MailItem)
                {
                    Outlook.MailItem mailItem =
                        (selObject as Outlook.MailItem);
                    itemMessage = "The item is an e-mail message." +
                        " The subject is " + mailItem.Subject + ".";
                    mailItem.Display(false);
                }
                else if (selObject is Outlook.ContactItem)
                {
                    Outlook.ContactItem contactItem =
                        (selObject as Outlook.ContactItem);
                    itemMessage = "The item is a contact." +
                        " The full name is " + contactItem.Subject + ".";
                    contactItem.Display(false);
                }
                else if (selObject is Outlook.AppointmentItem)
                {
                    Outlook.AppointmentItem apptItem =
                        (selObject as Outlook.AppointmentItem);
                    itemMessage = "The item is an appointment." +
                        " The subject is " + apptItem.Subject + ".";
                }
                else if (selObject is Outlook.TaskItem)
                {
                    Outlook.TaskItem taskItem =
                        (selObject as Outlook.TaskItem);
                    itemMessage = "The item is a task. The body is "
                        + taskItem.Body + ".";
                }
                else if (selObject is Outlook.MeetingItem)
                {
                    Outlook.MeetingItem meetingItem =
                        (selObject as Outlook.MeetingItem);
                    itemMessage = "The item is a meeting item. " +
                         "The subject is " + meetingItem.Subject + ".";
                }

有关详细信息,请参阅How to: Programmatically Determine the Current Outlook Item

答案 1 :(得分:0)

在弹出菜单事件处理程序中使用Explorer.Selection - 可以选择一条消息,然后右键单击另一条消息而不选择它。 Explorer.Selection集合不会更改,Explorer.SelectionChange事件也不会触发。

处理事件处理程序时,Context参数将传递给您。将其转换为Selection对象并改为使用它。该集合将与Explorer.Selection对象不同。