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?