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.
Related content
Feedback
https://aka.ms/ContentUserFeedback.
Coming soon: Throughout 2024 we will be phasing out GitHub Issues as the feedback mechanism for content and replacing it with a new feedback system. For more information see:Submit and view feedback for