Zar*_*kos 2 c# outlook add-in mailitem
我想从我的 Outlook 加载项中选择一个邮件项目。我知道如何从 C# 显示邮件项目,但我需要在 Outlook 窗口本身中选择它。
显示邮件项目:
mailItem.Display();
Run Code Online (Sandbox Code Playgroud)
我正在使用 Outlook 2010 加载项。
有人知道如何做到这一点吗?
使用Explorer.ClearSelection()然后Explorer.AddToSelection()。Explorer.IsItemSelectableInView()您应该在调用之前使用AddToSelection()以确保您要选择的项目存在于当前资源管理器视图中。
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);
Run Code Online (Sandbox Code Playgroud)
要更改当前Explorer视图,您可以使用Explorer.CurrentFolder或Explorer.CurrentView