2013-05-09 34 views
0

我正在使用VS 2010,Dot Net Framework 2.0。我在Extensibility-> Shared Add-ins for Outlook中創建了一個項目。保存Mailitem的對象或任何可用於調用已保存的Mailitem的屬性

我想在explorer_SelectionChange()的DataTable中保存Outlook.MailItem對象,並使用此Outlook.MailItem對象來處理主題和正文後面的內容。

當我保存數據表中的Mailitem對象時,它被保存爲SYS.ComAddins。 這裏是代碼 類變量:

private Outlook.MailItem connectingMailItem; 
private Outlook.Inspectors inspectors; 
private Outlook.Application applicationObject; 
private object addInInstance; 
private Outlook.Explorer explorer; 
DataTable dtMailItem = new DataTable(); 

的OnConnection:

explorer = this.Application.ActiveExplorer(); 
    explorer.SelectionChange += new Outlook.ExplorerEvents_10_SelectionChangeEventHandler(explorer_SelectionChange); 
    dtMailItem.Columns.Add("MailItem",typeOf(Outlook.MailItem)); 
    tFollowUp = new Timer(); 
    tFollowUp.Interval = 100000; 
    tFollowUp.Tick += new EventHandler(tFollowUp_Tick); 

explorer_SelectionChange

void explorer_SelectionChange() 
{ 
    if (connectingMailItem != null && connectingMailItem is Outlook.MailItem) 
    { 
     Marshal.ReleaseComObject(connectingMailItem); 
     // Perform a Garbage Collection 
     GC.Collect(); 
     connectingMailItem = null; 
     return; 
    } 
    foreach (object selectedItem in explorer.Selection) 
    { 
     connectingMailItem = selectedItem as Outlook.MailItem; 
     break; 
    } 
    if (connectingMailItem != null && connectingMailItem is Outlook.MailItem) 
    {     
     dtMailItem.Rows.Add(connectingMailItem); 
     dtMailItem.AcceptChanges(); 
    } 
} 

tFollowUp_Tick

void tFollowUp_Tick(object sender, EventArgs e) 
{ 
    if(dtMailItem.Rows.Count <= 0) 
    { 
     foreach(DataRow dr in dtMailItem.Rows) 
     { 
      // Manipulation code for subject and body or remove the Mailitem from Datatable 
     } 
    } 
} 

如何保存Mailitem或任何屬性的對象以識別哪個Mailitem已保存

+0

對不起,我不明白你的問題。你可以發佈一些代碼來解釋你試圖得到的結果嗎? – Fabske 2013-05-09 11:52:47

回答

1

您可以嘗試this question中建議的內容以存儲EntryID,並稍後使用相同的ID檢索它。