Difference between Outlook.Folder and Outlok.MAPIFolder

青春壹個敷衍的年華 提交于 2019-12-03 10:39:11

问题


I'm not clear on the difference between the classes Folder and MAPIFolder in the namespace Outlook. When I review the code in the net, some use the first, while others use the other syntax and I can't really determine if:

  • it's just because of their ignorance (and even less I can tell which group is the right one)
  • it's some kind of legacy (usage for different versions of Outlook)
  • it's the very same thing (something I'm fairly sure isn't true but one never knows)
  • it's an inheritance structure (and what to use when)
  • it's simply a way to avoid type issues (casting and as-ing)
  • it's other reason(s) entirely (and if so, which)

Here's the code I'm using for obtaining those two.

Outlook.Folder defaultContactsFolder_1 = 
  this.Application.Session.GetDefaultFolder(
    Outlook.OlDefaultFolders.olFolderContacts) as Outlook.Folder;

Outlook.MAPIFolder defaultContactFolder_2 = 
  this.Application.GetNamespace("MAPI").GetDefaultFolder(
    Outlook.OlDefaultFolders.olFolderContacts);

回答1:


Folder has superseded MAPIFolder which is now deprecated. See related SO post. Folder has additional event hooks as compared to MAPIFolder

Application.Session == Application.GetNamespace("MAPI") - they are interchangeable. See related SO post.

MAPIFolder and GetNamespace() are carry overs from Outlook 2003 and below - they've just been kept for backwards compatibility. There's no way to avoid type casting with VSTO - you will constantly be boxing and unboxing.



来源:https://stackoverflow.com/questions/12347640/difference-between-outlook-folder-and-outlok-mapifolder

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!