MAPI find the contacts and calendar folder

Posted by Rogier21 on Stack Overflow See other posts from Stack Overflow or by Rogier21
Published on 2010-05-19T20:06:00Z Indexed on 2010/05/19 23:00 UTC
Read the original article Hit count: 276

Filed under:
|
|

In my outlook I have 1 exchange connection and 2 Personal Folders.

I want to go fetch ALL items from the calendars and contacts so I use:

           /**
             * Create outlook application
             */
            Outlook.Application oApp = new Outlook.Application();
            Outlook.NameSpace oNS = oApp.GetNamespace("mapi");
            oNS.Logon(Missing.Value, Missing.Value, true, true);

            /**
             * Loop through all the folders
             */
            foreach (Outlook.MAPIFolder oFolder in oNS.Folders)
            {
                if (oFolder.Name == "Public Folders")
                {
                    break;
                }

                /**
                 * Get calendar items
                 */
                //Outlook.MAPIFolder oCalendar = oNS.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderCalendar);
                Outlook.MAPIFolder oCalendar = oFolder.Folders[5];
                Outlook.Items oCalendarItems = oCalendar.Items;

                //Outlook.MAPIFolder oContacts = oNS.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderContacts);
                Outlook.MAPIFolder oContacts = oFolder.Folders[7];
                Outlook.Items oContactItems = oContacts.Items;

But this does not work oFolder.Folders[5] is not always 5 for the calendar, sometimes it's a different value.

I cannot find the items by name oFolder.Folders["Calendar"]; because in Dutch the folder will be named "Agenda".

Usually I use: Outlook.MAPIFolder oCalendar = oNS.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderCalendar);

But then I only get the default calendar. How can I get the other calendars?

© Stack Overflow or respective owner

Related posts about c#

Related posts about outlook