2012-05-04 98 views
0

我真的是新增加的东西。我的代码应该这样做: 一个outlook用户保存/创建任何东西。如果创建的项目是预约项目,我的系统必须将其保存在c:目录下,将项目主题作为文件名称。这是我的代码。那里有什么问题?Outlook日历加载项

注意:当我创建一个新约会时,if子句正在工作,如果我写了其他任何代码,它正在工作,但我无法获取ai的信息,例如ai.Subject

namespace SendToMRBS 
{ 
    public partial class ThisAddIn 
    { 
     private void ThisAddIn_Startup(object sender, System.EventArgs e) 
     { 
      this.Application.ItemLoad += new Outlook.ApplicationEvents_11_ItemLoadEventHandler(Application_ItemLoad); 
    } 

    void Application_ItemLoad(object Item) 
    { 
     if (Item is Outlook.AppointmentItem) 
     { 
      Outlook.AppointmentItem ai = Item as Outlook.AppointmentItem; 
      ai.SaveAs("C:\\" + ai.Subject, Microsoft.Office.Interop.Outlook.OlSaveAsType.olICal); 
     } 
    } 


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

    #region VSTO generated code 

    /// <summary> 
    /// Required method for Designer support - do not modify 
    /// the contents of this method with the code editor. 
    /// </summary> 
    private void InternalStartup() 
    { 
     this.Startup += new System.EventHandler(ThisAddIn_Startup); 
     this.Shutdown += new System.EventHandler(ThisAddIn_Shutdown); 
    } 

    #endregion 

} 

}

回答

0

我找到了解决方案。该项目对象没有属性什么的,所以我不得不使用NewInspector事件。这里是我的新代码:

public partial class ThisAddIn 
{ 

    private void ThisAddIn_Startup(object sender, System.EventArgs e) 
    { 
     this.Application.ItemLoad += new Outlook.ApplicationEvents_11_ItemLoadEventHandler(Application_ItemLoad); 

    } 

    void Application_ItemLoad(object Item) 
    { 
     if (Item is Outlook.AppointmentItem) 
     { 
      this.Application.Inspectors.NewInspector += new Outlook.InspectorsEvents_NewInspectorEventHandler(Inspectors_NewInspector); 
     } 
    } 

    void Inspectors_NewInspector(Outlook.Inspector Inspector) 
    { 
     Outlook.AppointmentItem ai = Inspector.CurrentItem; 
     ai.Write += new Outlook.ItemEvents_10_WriteEventHandler(ai_Write); 
    } 

    void ai_Write(ref bool Cancel) 
    { 
     Outlook.Inspector ins = this.Application.ActiveInspector(); 
     Outlook.AppointmentItem appi = ins.CurrentItem; 

     appi.SaveAs("c:\\test.ics", Microsoft.Office.Interop.Outlook.OlSaveAsType.olICal); 
    } 

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

    #region VSTO generated code 

    /// <summary> 
    /// Required method for Designer support - do not modify 
    /// the contents of this method with the code editor. 
    /// </summary> 
    private void InternalStartup() 
    { 
     this.Startup += new System.EventHandler(ThisAddIn_Startup); 
     this.Shutdown += new System.EventHandler(ThisAddIn_Shutdown); 
    } 

    #endregion 

}