更改Outlook Mailitem选择C# [英] Change outlook mailitem selection c#

查看:284
本文介绍了更改Outlook Mailitem选择C#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从我的Outlook加载项中选择一个mailItem. 我知道如何从c#中显示邮件项目,但是我需要在Outlook窗口本身中选择它.

I want to select a mailItem from my outlook add-in. I know how to display a mailitem from c# but I need to select it inside the outlook window itself.

显示邮件项:

mailItem.Display();

我正在使用Outlook 2010加载项.

I am using the Outlook 2010 Add-in.

有人对如何执行此操作有任何想法吗?

Anybody has any idea on how to do this?

推荐答案

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

Use Explorer.ClearSelection() and then Explorer.AddToSelection(). You should use Explorer.IsItemSelectableInView() before calling AddToSelection() to ensure the item you want to select exists in the current explorer view.

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

Application.ActiveExplorer() will give you the current active explorer if it exists.

这是一个从此处获取的示例代码段(稍作修改即可检查IsItemSelectableInView ).

Here is a sample snippet taken from here (slightly modified to check 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

To change the current Explorer view you can use Explorer.CurrentFolder or Explorer.CurrentView

这篇关于更改Outlook Mailitem选择C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆