更改 Outlook 邮件项目选择 c#
本文关键字:选择 项目 Outlook 更改 | 更新日期: 2023-09-27 18:31:32
我想从我的 Outlook 加载项中选择一个邮件项目。我知道如何显示来自 c# 的邮件项目,但我需要在 Outlook 窗口本身中选择它。
显示邮件项目:
mailItem.Display();
我正在使用 Outlook 2010 加载项。
有人知道如何做到这一点吗?
使用 Explorer.ClearSelection()
然后Explorer.AddToSelection()
。在调用AddToSelection()
之前,应使用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.CurrentFolder
或Explorer.CurrentView