0
votes

I want to get a list of all of the calendars (folders) in my outlook and put them into a combo box. I have a top level Idea of how to do it, but I don't know enough about the Microsoft.Office.Interop.Outlook; to get the data. I'm sure it will be some kind of a for each combobox1.Items.add(Calendar);

Full disclosure: It is my plan to write a form application that will have a combobox to select the folder, another to select the items, and then populate the form from the item selected.

private void button2_Click(object sender, EventArgs e)
    {
        Microsoft.Office.Interop.Outlook.Application oApp = null;
        Microsoft.Office.Interop.Outlook.NameSpace mapiNamespace = null;
        Microsoft.Office.Interop.Outlook.MAPIFolder CalendarFolder = null;
        Microsoft.Office.Interop.Outlook.Items outlookCalendarItems = null;

        oApp = new Microsoft.Office.Interop.Outlook.Application();
        //mapiNamespace = oApp.GetNamespace("MAPI"); ;
        //CalendarFolder = mapiNamespace.GetDefaultFolder(Microsoft.Office.Interop.Outlook.OlDefaultFolders.olFolderCalendar);
        CalendarFolder = mapiNamespace.GetDefaultFolder(Microsoft.Office.Interop.Outlook.OlDefaultFolders.olFolderCalendar);
        outlookCalendarItems = CalendarFolder.Items;
        outlookCalendarItems.IncludeRecurrences = true;

        foreach (Microsoft.Office.Interop.Outlook.MAPIFolder item in CalendarFolder)
        {

        }
    }
1
Apparently I can't enumerate a MAPIFolder object... :-(william_perry

1 Answers

0
votes

To get all sub-folders of the Calendar folder, use:

var oApp = new Microsoft.Office.Interop.Outlook.Application();
var mapiNamespace = oApp.GetNamespace("MAPI");
var calendarFolder = mapiNamespace.GetDefaultFolder(Microsoft.Office.Interop.Outlook.OlDefaultFolders.olFolderCalendar);

foreach (Microsoft.Office.Interop.Outlook.MAPIFolder folder in calendarFolder.Folders)
{
    Console.WriteLine($"{folder.Name}");
}

Tested with Outlook 2013 and 2016:

Outlook sub-calendar

Prints

Cal1