1

我有这个“简单”的 Outlook 对象:

Outlook.Explorer olExplorer = this.Application.ActiveExplorer();

在“ThisAddin_StartUp”中,我将olExplorer.FolderSwitch事件注册到函数 olExplorer_FolderSwitch()。我必须从当前文件夹创建一个 Outlook 文件夹对象:

Outlook.Folder f = olExplorer.CurrentFolder as Outlook.Folder;

但是:属性 "CurrentFolder" 属于 MAPIFolder 类型,不能用作Outlook.Folder。如何将 CurrentFolder-Property“投射”到 Outlook.Folder?- 不丢失事件处理程序?如果我做这个简单的转换,对象f将不会触发事件 BeforeItemMove - 因为f是 NULL 而 olExplorer.CurrentFolder 不是

4

4 回答 4

1

我还没有找到一个简单的方法。您可以从文件夹会话中找到 Outlook.Folder。

如果您比较 EntryID,您将获得正确的文件夹。

Outlook.Folders olFolders = OutlookApp.Session.Folders;

for (int i = 1; i <= olFolders.Count; i++)
{
   if (olFolders[i].EntryID == olExplorer.CurrentFolder.EntryID)
   {
      // folder found assign and use it.
   }
}

注意从 1 开始并计数等于或小于以获取所有文件夹。

于 2009-05-21T14:33:01.050 回答
1

有简单的方法将 MAPIFolder 转换为 Outlook.Folder 尝试显式转换:

Outlook.Explorer olExplorer = this.Application.ActiveExplorer();
Outlook.Folder f = (Outlook.Folder)olExplorer.CurrentFolder;
于 2012-01-04T15:01:10.823 回答
0

我真的不明白这个问题,因为根据文档 Explorer.CurrentFolder 返回 Outlook.Folder 类型的对象,而不是 MAPIFolder。我个人没有做过任何 VSTO(也没有特定于 2007)的开发,但你确定你没有混淆不同版本的对象模型吗?

无论如何,Outlook.Folder 和 MAPIFolder 共享 EntryID 和 StoreID 属性。您可以使用它们来使用NameSpace.GetFolderFromID查找相应的 Outlook.Folder 。有问题的命名空间是通过 Application.GetNamespace("MAPI") 获取的。

于 2009-04-07T18:47:00.130 回答
0

Outlook.Folder 与 Outlook.MAPIFolder 相同。

于 2012-01-05T06:41:48.150 回答