c# - 如何以编程方式选择要在 Outlook 2010 中查看的文件夹?

标签 c# outlook vsto outlook-2010

我正在通过 Search.Save 方法以编程方式创建搜索文件夹。保存搜索后(它在“搜索文件夹”目录中创建一个新文件夹),我想将焦点设置在这个新创建的文件夹上,以便 View 更改为该文件夹。

这是我到目前为止的代码......

searchFolders = inboxFolder.Store.GetSearchFolders();
foreach (Outlook.Folder folder in searchFolders)
{
    if (folder.Name == "Expiring Retention Policy Mail")
    {
        folder.ShowItemCount = Microsoft.Office.Interop.Outlook.OlShowItemCount.olShowTotalItemCount;
        //folder.SetCustomIcon(new Bitmap(32, 32));
        folder.Display();
    }
}

当我执行 folder.Display() 时,它会打开一个全新的检查器窗口...我不想发生这种情况,我只是想选择它(比如通过设置焦点?)并在它存在于同一个检查器窗口中。有人知道该怎么做吗?

谢谢。

最佳答案

这应该对你有用...

访问您的Application 对象(或从主加载项类)。然后

this.Application.ActiveExplorer().CurrentFolder = folder;  

即您可以使用 ActiveExplorer

CurrentFolder

Of course, always make sure to properly release your COM objects (the ones that need releasing) - and you should never do it like I did here (for simplicity) - i.e. chaining properties like that. Save each (property) into a variable, and release via Marshal.ReleaseComObject on your way out.

关于c# - 如何以编程方式选择要在 Outlook 2010 中查看的文件夹?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16113984/

相关文章:

c# - 可以快速调整大小的数组

c# - DateTime.Now 和文化/时区特定

visual-studio-2010 - Windows 7 下的 ClickOnce/Excel-VSTO

c# - Word VSTO 加载项 : How to set the width of a custom task pane?

c# - c# 中类、函数、变量等的正确命名符号是什么?

c# - Visual Studio 可以将项目引用编译到不同的文件夹然后是主 .exe

excel - 如果单元格的值为 = 1,则将电子邮件地址添加到 Outlook 电子邮件

vba - 为什么同一个Err.Description有多个Err.Number?

vba - 将当前电子邮件中的附件保存到派生文件夹中。

excel - 使用 VSTO 2008 加载项在 Excel 2007 中将 .NET 方法显示为 UDF