2012-05-04 2 views
0

나는 추가 기능에 정말 새로운 기능을 제공합니다. 내 코드는 다음을 수행해야합니다. Outlook 사용자가 아무 것도 저장/생성하지 않습니다. 생성 된 항목이 약속 항목 인 경우 시스템은 항목 제목을 파일 이름으로 사용하여 c : 디렉토리 아래에 저장해야합니다. 여기 내 코드가있다. 거기에 뭐가 잘못 되었나요?캘린더 용 Outlook 추가 기능

참고 : 새 약속을 만들 때 if 절이 작동합니다. 다른 코드를 작성하면 작동하지만, 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 

}