【问题标题】:How to open appointment item from ribbon button click如何从功能区按钮单击打开约会项目
【发布时间】:2018-05-21 06:09:50
【问题描述】:

我需要通过单击功能区按钮打开 Outlook 约会项目。

var item = control.Context as Inspector;
AppointmentItem appointmentItem = item.CurrentItem as AppointmentItem;
    if (appointmentItem != null)
        {
            if (appointmentItem.EntryID == null)
            {
                appointmentItem.Subject = "New Appointment";
                appointmentItem.Body = "Welcome to new appointment";
            }
        }

它应该打开约会窗口,但它给出了空引用错误,就像这行代码“var item = control.Context as Inspector;”一样该项目为空。

【问题讨论】:

    标签: vsto outlook-2016 ribbonx


    【解决方案1】:

    这是一个 XML 代码示例。

    <?xml version="1.0" encoding="UTF-8"?>
    <customUI xmlns="http://schemas.microsoft.com/office/2009/07/customui" onLoad="Ribbon_Load">
      <ribbon>
        <tabs>
          <tab idMso="TabAddIns">
            <group id="MyGroup"
                   label="My Group">
                                <button
                                        id="btnNewAppointment"
                                        label="New Appointment"
                                        onAction="NewAppointment"
                                        imageMso="NewAppointment"
                                        size="large"
                                        screentip="New Appointment"
                                        supertip="Create a new appointment"
                                        />
            </group>
          </tab>
        </tabs>
      </ribbon>
    </customUI>
    

    这是一个 C# 代码示例。

    public void NewAppointment(Office.IRibbonControl control)
    {
        try
        {
            Microsoft.Office.Interop.Outlook.Application app = Globals.ThisAddIn.Application;
            Microsoft.Office.Interop.Outlook.AppointmentItem newAppointment = (Microsoft.Office.Interop.Outlook.AppointmentItem)
            app.CreateItem(Microsoft.Office.Interop.Outlook.OlItemType.olAppointmentItem);
            newAppointment.Start = DateTime.Now.AddHours(2);
            newAppointment.End = DateTime.Now.AddHours(3);
            newAppointment.Location = "ConferenceRoom #2345";
            newAppointment.Body = "We will discuss progress on the group project.";
            newAppointment.AllDayEvent = false;
            newAppointment.Subject = "Group Project";
            newAppointment.Recipients.Add("Roger Harui");
            Microsoft.Office.Interop.Outlook.Recipients sentTo = newAppointment.Recipients;
            Microsoft.Office.Interop.Outlook.Recipient sentInvite = null;
            sentInvite = sentTo.Add("Holly Holt");
            sentInvite.Type = (int)Microsoft.Office.Interop.Outlook.OlMeetingRecipientType.olRequired;
            sentInvite = sentTo.Add("David Junca ");
            sentInvite.Type = (int)Microsoft.Office.Interop.Outlook.OlMeetingRecipientType.olOptional;
            sentTo.ResolveAll();
            newAppointment.Save();
            newAppointment.Display(true);
        }
        catch (Exception ex)
        {
            //MessageBox.Show("The following error occurred: " + ex.Message);
        }
    }
    

    这是来自微软How to: Programmatically Create Appointments的文章

    【讨论】:

      猜你喜欢
      • 2013-11-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-07-23
      • 1970-01-01
      • 1970-01-01
      • 2022-10-02
      相关资源
      最近更新 更多