How to: Get a Default Folder and Enumerate Its Subfolders

This example shows how to obtain a default folder in the user’s default store and enumerate its subfolders.

Programming Applications for Office Outlook 2007

The following code example is an excerpt from Programming Applications for Microsoft Office Outlook 2007, from Microsoft Press (ISBN 9780735622494, copyright Microsoft Press 2007, all rights reserved).

Buy this book

Sample chapters

In the following code example, GetRSSFeeds uses the GetDefaultFolder(OlDefaultFolders) method of the NameSpace object to obtain the user’s RSS Feeds root folder. GetRSSFeeds then displays a message box that contains the folder names for all RSS feeds in the RSS Feeds folder.

If you use Microsoft Visual Studio to test this code example, you must first add a reference to the Microsoft Outlook 14.0 Object Library component and specify the Outlook variable when you import the Microsoft.Office.Interop.Outlook namespace. The using statement must not occur directly before the functions in the code example but must be added before the public Class declaration. The following line of code shows how to do the import and assignment in C#.

using Outlook = Microsoft.Office.Interop.Outlook;
private void GetRSSFeeds()
    Outlook.Folder folder =
        as Outlook.Folder;
    if (folder != null)
        if (folder.Folders.Count > 0)
            StringBuilder sb = new StringBuilder();
            foreach (Outlook.Folder subfolder
                in folder.Folders)
                "RSS Feeds",

Other Resources