2012-05-04 3 views
0

Je suis vraiment nouveau dans le domaine des add-in. Mon code devrait faire ceci: Un utilisateur de perspectives sauve/crée n'importe quoi. Si l'élément créé est un élément de rendez-vous, mon système doit l'enregistrer sous le répertoire c: en prenant l'objet comme nom de fichier. Voici mon code. Quel est le problème ici? Remarque: lorsque je crée un nouveau rendez-vous, la clause if fonctionne, si j'écris un autre code, cela fonctionne, mais je ne peux pas obtenir les informations de ai, telles que ai.Subject.Add-in Outlook pour le calendrier

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 

} 

}

Répondre

0

J'ai trouvé la solution .. L'objet de l'article n'a pas de propriétés ou quelque chose, alors je devais utiliser événement NewInspector. Voici mon nouveau code:

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 

} 
Questions connexes