Compartir a través de


How to: Programmatically retrieve a folder by name

Applies to: yesVisual Studio noVisual Studio for Mac

Note

This article applies to Visual Studio 2017. If you're looking for the latest Visual Studio documentation, see Visual Studio documentation. We recommend upgrading to the latest version of Visual Studio. Download it here

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.

Example

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

Compile the code

This example requires:

  • A folder named TestFolder.

See also