我想从我的 Outlook 加载项中选择一个邮件项目。 我知道如何从 C# 显示邮件项目,但我需要在 Outlook 窗口本身中选择它。
显示邮件项目:
mailItem.Display();
我正在使用 Outlook 2010 加载项。
有人知道如何做到这一点吗?
最佳答案
使用Explorer.ClearSelection()
然后Explorer.AddToSelection()
。您应该使用 Explorer.IsItemSelectableInView()
在调用 AddToSelection()
之前确保您要选择的项目存在于当前资源管理器 View 中。
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
View ,您可以使用 Explorer.CurrentFolder
或Explorer.CurrentView
关于c# - 更改 Outlook 邮件项目选择 C#,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10205103/