2
我想从我的Outlook加载项中选择一个mailItem。 我知道如何显示从c#中的mailitem,但我需要在Outlook窗口本身内部选择它。更改outlook mailitem选择c#
显示的MailItem:
mailItem.Display();
我使用的是Outlook 2010的插件。
任何人有什么想法如何做到这一点?
我想从我的Outlook加载项中选择一个mailItem。 我知道如何显示从c#中的mailitem,但我需要在Outlook窗口本身内部选择它。更改outlook mailitem选择c#
显示的MailItem:
mailItem.Display();
我使用的是Outlook 2010的插件。
任何人有什么想法如何做到这一点?
使用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.CurrentFolder
或Explorer.CurrentView
甜的人:) THX! (srr为延迟响应,但我忙于其他东西) – Zarkos 2012-05-09 08:20:58
函数Application.ActiveExplorer()将无法在对话视图下工作 – phuongnd 2017-02-14 07:04:03
您从哪里获取OutlookApp? – 2017-08-15 02:05:52