C#Outlook Addin setCurrentFormPage抛出异常

时间:2015-09-16 15:05:04

标签: c# vsto outlook-addin outlook-2007

我正在使用 VSTO 开发 outlook 的插件,我正在尝试将单独的表单区域显示为打开检查器中的当前表单页面但是抛出一个例外。这是代码

    private void ThisAddIn_Startup(object sender, System.EventArgs e)
    {
        this.Application.Inspectors.NewInspector += InspectorsOnNewInspector;
        this.Application.Explorers.NewExplorer +=  Explorers_NewExplorer;
    }

    private void Explorers_NewExplorer(Outlook.Explorer explorer)
    {

    }

    private void InspectorsOnNewInspector(Outlook.Inspector inspector)
    {
        MessageBox.Show("ola");
        // exception ocurrs in this line 
        inspector.SetCurrentFormPage("OutlookAddIn.RequestFormRegion");

    }

    private void ThisAddIn_Shutdown(object sender, System.EventArgs e)
    {
    }

提前致谢。

1 个答案:

答案 0 :(得分:0)

我设法使用以下代码

 private void InspectorsOnNewInspector(Outlook.Inspector inspector)
    {

        MessageBox.Show("ola");

        if (!(inspector.CurrentItem is Outlook.TaskItem)) return;

        var taskItem = (Outlook.TaskItem) inspector.CurrentItem;

        taskItem.Open += (ref bool cancel) =>
        {
            try
            {
                inspector.SetCurrentFormPage("OutlookAddIn.RequestFormRegion");

            }
            catch (Exception ex)
            {
                System.Windows.Forms.MessageBox.Show(ex.Message);
            }
        };
    }