共用方式為


在列舉資料夾中的專案時,篩選並顯示多重值屬性

此範例示範如何在列舉資料夾中的項目時篩選及顯示多重值屬性。

範例

注意事項

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

Table 物件代表 FolderSearch 物件中的一組項目數據。 當二進位、日期或多重值屬性第一次加入 Table 物件時,參考屬性的方式會影響其類型和格式。 由於內建名稱參考有時會傳回與命名空間參照不同的數據行值,因此您應該判斷屬性是否由其明確內建名稱參考 (如果它有一個) ,還是由命名空間 (,而不論明確內建名稱) 是否存在。 下表顯示屬性值表示 (在每個原始屬性類型的類型和格式) 方面的差異。

類型

如果指定的屬性使用內建名稱,則傳回型別

如果指定的屬性使用命名空間,則傳回型別

二進 位 (PT_BINARY)

String

位元組陣列

日期 (PT_SYSTIME)

機 DateTime

UTC DateTime

多重值 (也稱為關鍵字類型) 例如 Categories 屬性 (PT_MV_STRING8)

包含逗號分隔值的字串

包含每個關鍵詞一個元素的一維數位列

下列程式代碼範例說明如何將MAPI字串命名空間屬性新增至 Table 物件,以及多重值屬性如何影響 Column 物件中傳回的值。 TableMultiValuedProperties 程式會針對 Categories 屬性不是 Null 參考的數據列篩選 Table 物件。 Categories 屬性是由使用MAPI字串命名空間的屬性表示。 DAV 搜尋和尋找 (DASL) 篩選器是針對具有類別的專案建構, (實際篩選會傳回沒有 null 參考) 的類別。 接著會將 Categories 數據行與 categoriesProperty 常數串連類型規範 0000001f,以新增至 Table 物件。 最後,代表 Categories 屬性的 Column 物件包含一維字串數位,其中陣列的每個元素都代表指派給項目的類別。 專案的 CategoriesSubject 屬性都會寫入接聽程式集合的追蹤接 程式。

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 TableMultiValuedProperties()
{
    const string categoriesProperty =
        "http://schemas.microsoft.com/mapi/string/"
        + "{00020329-0000-0000-C000-000000000046}/Keywords";
    // Inbox
    Outlook.Folder folder =
        Application.Session.GetDefaultFolder(
        Outlook.OlDefaultFolders.olFolderInbox)
        as Outlook.Folder;
    // Call GetTable with filter for categories
    string filter = "@SQL="
        + "Not(" + "\"" + categoriesProperty
        + "\"" + " Is Null)";
    Outlook.Table table =
        folder.GetTable(filter,
        Outlook.OlTableContents.olUserItems);
    // Add categories column and append type specifier
    table.Columns.Add(categoriesProperty + "/0000001F");
    while (!table.EndOfTable)
    {
        Outlook.Row nextRow = table.GetNextRow();
        string[] categories =
            (string[])nextRow[categoriesProperty + "/0000001F"];
        Debug.WriteLine("Subject: " + nextRow["Subject"]);
        Debug.Write("Categories: ");
        foreach (string category in categories)
        {
            Debug.Write("\t" + category);
        }
        Debug.WriteLine("\n");
    }
}

另請參閱