共用方式為


使用立即搜尋來搜尋主旨中詞組的所有資料夾和所有存放區

此範例會使用 「立即搜尋」來搜尋主旨中片組的所有資料夾和所有存放區,然後在總管視窗中顯示專案。

範例

注意事項

下列程式代碼範例是 Microsoft Office Outlook 2007 程式設計應用程式的摘錄。

「立即搜尋」是 Microsoft Outlook 的一項功能,可讓您藉由發出根據內容傳回結果的查詢來進行搜尋。 一旦處理查詢之後,就可以在各種物件中傳回結果,包括 Table 物件、 Items 集合和 Search 物件。 您可以使用 Microsoft Windows 桌面搜尋所提供的進階查詢語法 (AQS) ,撰寫使用「立即搜尋」的程式代碼。 AQS 是 Outlook 支援的三種查詢語言之一。 它很強大,但僅限於 Explorer 物件的 Search (String、OlSearchScope) 方法。 您無法使用 AQS 來提供 TableItem 物件的限制。 此外,AQS 查詢傳回的結果只能顯示在 Outlook 使用者介面中。 下表列出 Outlook 支援的三種查詢語言:不過,本主題將說明僅使用 AQS。

查詢語言

描述

AQS

AQS 是由 Windows 桌面搜尋所使用,是 Outlook 中 [立即搜尋] 功能的查詢語言。

DASL

DAV 搜尋和尋找 (DASL) 查詢語言是以 Outlook 中 DASL 的 Microsoft Exchange 實作為基礎。 DASL 可用來傳回 Table 物件中的結果。

射流

Jet 查詢語言為 Outlook 提供簡單的查詢語言,並以 Microsoft Jet 表達式服務為基礎。 Jet 可用來建立 Items 集合和 Table 物件之 Restrict 方法的篩選字串。

在下列程式代碼範例中,DemoInstantSearch 會使用 Store 物件的 IsInstantSearchEnabled 屬性,取得所有存放區中啟用索引的所有郵件資料夾。 然後,它會使用 Explorer 物件的 Search 方法來篩選主旨中包含確切片語 “Office 2007” 且在過去一個月收到的所有專案。 搜尋結果最後會顯示在個別的檔案總管視窗中。

If you use Visual Studio to test this code example, you must first add a reference to the Microsoft Outlook 15.0 Object Library component and specify the Outlook variable when you import the Microsoft.Office.Interop.Outlook namespace. The using statement must not occur directly before the functions in the code example but must be added before the public Class declaration. The following line of code shows how to do the import and assignment in C#.

using Outlook = Microsoft.Office.Interop.Outlook;
private void DemoInstantSearch()
{
    if (Application.Session.DefaultStore.IsInstantSearchEnabled)
    {
        Outlook.Explorer explorer = Application.Explorers.Add(
            Application.Session.GetDefaultFolder(
            Outlook.OlDefaultFolders.olFolderInbox)
            as Outlook.Folder,
            Outlook.OlFolderDisplayMode.olFolderDisplayNormal);
        string filter = "subject:" +
            "\"" + "Office 2007" + "\"" +
            " received:(last month)";
        explorer.Search(filter,
            Outlook.OlSearchScope.olSearchScopeAllFolders);
        explorer.Display();
    }
}

另請參閱