Konrad Viltersten
Konrad Viltersten

Reputation: 39298

Difference between Outlook.Folder and Outlok.MAPIFolder

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:

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);

Upvotes: 15

Views: 12171

Answers (1)

SliverNinja - MSFT
SliverNinja - MSFT

Reputation: 31651

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.

Upvotes: 20

Related Questions