2012-04-18 80 views
2

我想從我的Outlook加載項中選擇一個mailItem。 我知道如何顯示從c#中的mailitem,但我需要在Outlook窗口本身內部選擇它。更改outlook mailitem選擇c#

顯示的MailItem:

mailItem.Display(); 

我使用的是Outlook 2010的插件。

任何人有什麼想法如何做到這一點?

回答

4

使用Explorer.ClearSelection()然後Explorer.AddToSelection()。在撥打AddToSelection()之前,您應該使用Explorer.IsItemSelectableInView()以確保您想要選擇的項目存在於當前資源管理器視圖中。

Application.ActiveExplorer()會給你當前活動的瀏覽器,如果它存在。

這裏是一個sample snippet taken from here稍作修改,以檢查IsItemSelectableInView)。

Outlook._Explorer explorer = OutlookApp.ActiveExplorer(); // get active explorer 
explorer.ClearSelection(); // remove current selection 
Outlook.NameSpace ns = OutlookApp.Session; 
object item = ns.GetItemFromID(entryId, Type.Missing); // retrieve item 
if (explorer.IsItemSelectableInView(item)) // ensure item is in current view 
    explorer.AddToSelection(item); // change explorer selection 
else 
    // TODO: change current view so that item is selectable 
Marshal.ReleaseComObject(item); 
Marshal.ReleaseComObject(ns); 
Marshal.ReleaseComObject(explorer); 

要改變當前Explorer視圖,您可以使用Explorer.CurrentFolderExplorer.CurrentView

+1

甜的人:) THX! (srr爲延遲響應,但我忙於其他東西) – Zarkos 2012-05-09 08:20:58

+0

函數Application.ActiveExplorer()將無法在對話視圖下工作 – phuongnd 2017-02-14 07:04:03

+0

您從哪裏獲取OutlookApp? – 2017-08-15 02:05:52