2012-05-04 30 views
0

私はアドインのもので本当に新しいです。私のコードは次のようにしなければなりません。 Outlookユーザが何かを保存/作成しています。作成されたアイテムが予定アイテムである場合、私のシステムはアイテムの件名をファイル名としてc:ディレクトリに保存する必要があります。ここに私のコードです。何がそこに間違っていますか?予定表のOutlookアドイン

注:新しい予定を作成するときに、if節が動作していれば、他のコードを書き込んでも動作していますが、ai.SubjectなどのAI情報は取得できません。

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

私は解決策を見つけた... Itemオブジェクトにはプロパティか何かを持っていないので、私は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 

}