HOW TO:依名稱擷取資料夾

更新:2007 年 11 月

適用於

本主題中的資訊僅適用於指定的 Visual Studio Tools for Office 專案和 Microsoft Office 版本。

專案類型

  • 應用程式層級專案

Microsoft Office 版本

  • Outlook 2003

  • Outlook 2007

如需詳細資訊,請參閱依應用程式和專案類型提供的功能

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

範例

Private Sub SetCurrentFolder()
    Dim folderName As String = "TestFolder"
    Dim inBox As Outlook.MAPIFolder = Me.Application.ActiveExplorer().Session. _
        GetDefaultFolder(Outlook.OlDefaultFolders.olFolderInbox)
    Try
        Me.Application.ActiveExplorer().CurrentFolder = inBox.Folders(folderName)
        Me.Application.ActiveExplorer().CurrentFolder.Display()
    Catch
        MessageBox.Show("There is no folder named " & folderName & _
            ".", "Find Folder Name")
    End Try
End Sub
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");
    }
}

編譯程式碼

這項範例需要:

  • 名為 TestFolder 的資料夾。

請參閱

工作

HOW TO:在特定資料夾中搜尋

HOW TO:搜尋特定的連絡人

HOW TO:建立自訂資料夾項目

概念

使用資料夾