VSTO Addin项目相关变量&呼叫物品识别

时间:2017-10-17 08:26:44

标签: vsto outlook-addin

我正在处理与日历约会相关的Outlook Addin。我的问题是我需要保存初始约会标题,然后检查保存是否更新以触发其他操作。我知道Addin / Ribbon只有一个实例。我最初使用静态变量,但它没有帮助,因为打开多个窗口然后标题混淆。我的问题是: 1)在哪里存储与约会相关的变量? 2)如何检测哪个对象一直在调用write / save / send / methods?

以下是我的代码的相关摘录:

public partial class ThisAddIn
{

    public static Outlook.AppointmentItem appointmentItem;
    public static Addin_Ribbon ribbon;
    Outlook.Inspectors inspectors;

// Needs to be saved for each appointments
public static string initialMeetingSubject = "";

    private void ThisAddIn_Startup(object sender, System.EventArgs e)
    {
        inspectors = this.Application.Inspectors;
        inspectors.NewInspector +=
        new Microsoft.Office.Interop.Outlook.InspectorsEvents_NewInspectorEventHandler(Inspectors_NewInspector);
    }

    protected override Microsoft.Office.Core.IRibbonExtensibility CreateRibbonExtensibilityObject()
    {
        ribbon = new MyAddin_Ribbon();
        return ribbon;
    }

    void Inspectors_NewInspector(Microsoft.Office.Interop.Outlook.Inspector Inspector)
    {
        // Save current appointment reference
        appointmentItem = Inspector.CurrentItem as Outlook.AppointmentItem;

        if (appointmentItem != null)
        {
            (appointmentItem as Microsoft.Office.Interop.Outlook.ItemEvents_10_Event).Send += _appointment_Send;
            (appointmentItem as Microsoft.Office.Interop.Outlook.ItemEvents_10_Event).BeforeDelete += _appointment_Delete;
            (appointmentItem as Microsoft.Office.Interop.Outlook.ItemEvents_10_Event).Write += _appointment_Write;    
            (appointmentItem as Microsoft.Office.Interop.Outlook.ItemEvents_10_Event).Open += _appointment_Open;
            (appointmentItem as Microsoft.Office.Interop.Outlook.ItemEvents_10_Event).Close += _appointment_Close;

            // Save initial value to compare during appointment save
            ThisAddIn.initialMeetingSubject = appointmentItem.Subject;

        }
    }

    private void _appointment_Write(ref bool Cancel)
    {
        Logger.WriteLine(LogLevel.Debug, "Appointment WRITE Initial Subject: " +initialMeetingSubject + “ Updated Subject: “ + ThisAddIn.appointmentItem.Subject);
    }
}

非常感谢任何帮助。

1 个答案:

答案 0 :(得分:0)

Ok我在之前的评论中发布的Microsoft教程实际上非常清晰且高效。按照说明,我为约会项目创建了一个包装类,它就像魅力一样。可以下载测试项目here