共用方式為


以程式設計方式依名稱擷取資料夾

此範例會取得具名自訂資料夾的參考,然後顯示該資料夾的內容。

適用對象: 本主題資訊適用於 Outlook 的 VSTO 增益集專案。 如需詳細資訊,請參閱依 Office 應用程式和專案類型提供的功能

範例

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");
    }
}

編譯程式碼

這個範例需要:

  • 名為 TestFolder 的資料夾。