更改outlook mailitem选择c#

我想从outlook加载项中选择一个mailItem。 我知道如何从c#显示mailitem,但我需要在outlook窗口中选择它。

显示mailitem:

mailItem.Display(); 

我正在使用Outlook 2010加载项。

任何人都知道如何做到这一点?

使用Explorer.ClearSelection()然后使用Explorer.AddToSelection() 。 在调用AddToSelection() Explorer.IsItemSelectableInView()之前,应使用Explorer.IsItemSelectableInView()以确保在当前资源管理器视图中存在要选择的项。

Application.ActiveExplorer()将为您提供当前活动的资源管理器(如果存在)。

以下是从此处获取的示例代码段 ( 稍作修改以检查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