4

Firstly , I am a freshmen to outlook add-in development,Recently I read some learning material from MSDN or other tutorial, The First thing makes me confused is if I want to find something like a certain Appointment or Meeting Request from inbox, I should firstly use Application.GetNameSpace(“MAPI”) to get a NameSpace instead of getting some kind of object like Folder or Appointment Collections and so on.

I don't understand the Data Store Access pattern of Outlook 2007 in Add-in development. I hope someone can help me better understand Data store access of outlook 2007.

SliverNinja - MSFT
  • 31,051
  • 11
  • 110
  • 173
malai.kuangren
  • 349
  • 4
  • 11

1 Answers1

3

A MAPI Session is required to interact with an Outlook Data Store. Application.Session is interchangeable with Application.GetNamespace("MAPI"). You can think of a session as a connection to the Outlook Data Store.

To retrieve appointments, you can use Namespace.GetDefaultFolder.

Outlook.Folder appointmentStore = Globals.ThisAddIn.Application.Session.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderCalendar) as Outlook.Folder;
string apptSubject = string.Empty;
foreach (Outlook.AppointmentItem appt in appointments.Items.OfType<Outlook.AppointmentItem>())
  apptSubject = appt.Subject;
SliverNinja - MSFT
  • 31,051
  • 11
  • 110
  • 173
  • Thanks, What do you mean `required` ? It means `better`? Actually I found someone uses `Application.GetNamespace("MAPI").GetDefaultFolder(olFolderTasks)` in some code examples instead of using the `Session`. – malai.kuangren Aug 15 '12 at 14:16
  • 1
    They are equivalent. `Session == GetNamespace("MAPI")` – SliverNinja - MSFT Aug 15 '12 at 14:22
  • So ,That means MAPI reference is the necessary thing on the learning path of Outlook 2007 add-in development. Is it Correct?Thanks – malai.kuangren Aug 15 '12 at 14:27
  • 1
    Yes - you need to reference a **MAPI Session** for many Outlook integration tasks. It depends on what customizations you are performing. – SliverNinja - MSFT Aug 15 '12 at 14:30
  • Hi ,Ninja, need you help check something, I think `session` is the MAPI Way to access outlook dataitems, and `GetNamespace` is the Object model and PIA another way . Is it correct? Thanks – malai.kuangren Aug 15 '12 at 15:03
  • [`Outlook.Namespace`](http://msdn.microsoft.com/en-us/library/microsoft.office.interop.outlook.namespace.aspx) is PIA (*Microsoft.Office.Interop.Outlook*). Both `Session` and `GetNamespace()` return `Outlook.Namespace`. **PIA** provides multiple ways of establishing a **MAPI Session**. – SliverNinja - MSFT Aug 15 '12 at 15:08
  • So, both are outlook object model and PIA ways to access data items, correct? – malai.kuangren Aug 15 '12 at 15:14
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/15382/discussion-between-malai-kuangren-and-sliverninja) – malai.kuangren Aug 15 '12 at 15:42