Outlook 2010 Add-In : Display Folders list using C#

Through my previous Articles, I have explained how to create an Outlook 2010 Add-In; explained how to add a button to Outlook 2010 Application, and also displayed the Subject of the selected Mail item.

In this article, I am going to explain, how to display the folders which are in Outlook 2010. Extending the example that I have mentioned in my previous Article “Outlook 2010 Add-In : Get MailItem using C#“, to display the list of Folders. When we click on the button, what we have added through the Article “Outlook 2010 Add-In : Add Button to Outlook using C#“; our Add-In will display a list of Folders available in Outlook 2010.

Step 1. Get the Explorer object from the Outlook Application object.

Outlook.Explorer explorer = Globals.ThisAddIn.Application.ActiveExplorer();

Step 2. Get the list of Folders that are available from the Explorer object.  But we can not get this directly; we must use its Session object. Explorer’s Session object; provide the list of Folders.

Explorer.Session.Folders

Step 3. Notice that, above statement returns the high-level folders; that means, mailboxes. For example, Main Mailbox, Archive Folders, etc,. Each mailbox directly references the “.ost” or “.pst” files. How do we get the “Inbox” folder then.? The next step explains this.

Step 4. Other folders like “Inbox”, “Outbox” etc., are the sub-folders inside the mailbox. The Folder object has the property Folders; contains the list of its sub-folders.

Folder.Folders

Step 5. We need to walk through each mailbox and display its’ folders. Putting all together, the code looks like below:

Step 6. After modifying our Outlook 2010 Add-In, with the above code; build & Run the Add-In. Once our button is added into Outlook 2010; click on the button to display the list of folders. The output is something like below:

Outlook 2010 Add-In - Outlook Folders
Outlook 2010 Add-In – Outlook Folders

I will explain more on Outlook 2010 Object Model, with examples; in my upcoming Articles.

(Raju)

Outlook 2010 Add-In : Display Folders list using C#

Leave a Reply

Your email address will not be published.

Scroll to top