How to: Programmatically Retrieve a Folder by Name

 

This example gets a reference to a named custom folder and then displays the contents of the folder.

Applies to: The information in this topic applies to VSTO add-in projects for Outlook. For more information, see Features Available by Office Application and Project Type.

        private void SetCurrentFolder()
        {
            string folderName = "TestFolder";
            Outlook.MAPIFolder inBox = (Outlook.MAPIFolder)
                this.Application.ActiveExplorer().Session.GetDefaultFolder
                (Outlook.OlDefaultFolders.olFolderInbox);
            try
            {
                this.Application.ActiveExplorer().CurrentFolder = inBox.
                    Folders[folderName];
                this.Application.ActiveExplorer().CurrentFolder.Display();
            }
            catch
            {
                MessageBox.Show("There is no folder named " + folderName +
                    ".", "Find Folder Name");
            }
        }

This example requires:

  • A folder named TestFolder.

Working with Folders
How to: Programmatically Search Within a Specific Folder
How to: Programmatically Search for a Specific Contact
How to: Programmatically Create Custom Folder Items

Show: