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.
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.