How to: Select a Folder and Display Folder Information

This example shows how to programmatically display information about a folder that a user selects from a specified folder list.

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, ShowFolderInfo uses the PickFolder() method of the NameSpace object to display a Select Folder dialog box to the user, and waits for the user to select a folder. Once the user selects a folder, its EntryID, StoreID, UnReadItemCount, DefaultMessageClass, CurrentView, Name, and FolderPath properties are displayed. The example then calls the GetFolderFromID method to create a new Folder object and display the 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 ShowFolderInfo()
    Outlook.Folder folder =
        as Outlook.Folder;
    if (folder != null)
        StringBuilder sb = new StringBuilder();
        sb.AppendLine("Folder EntryID:");
        sb.AppendLine("Folder StoreID:");
        sb.AppendLine("Unread Item Count: "
            + folder.UnReadItemCount);
        sb.AppendLine("Default MessageClass: "
            + folder.DefaultMessageClass);
        sb.AppendLine("Current View: "
            + folder.CurrentView.Name);
        sb.AppendLine("Folder Path: "
            + folder.FolderPath);
            "Folder Information",
        Outlook.Folder folderFromID =
            folder.EntryID, folder.StoreID)
            as Outlook.Folder;

Other Resources