共用方式為


在列舉資料夾中的項目時篩選和顯示計算屬性

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

範例

注意事項

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

Table 物件代表 FolderSearch 物件中的一組項目數據。 Row 物件代表 Table 中的數據列。 Columns 物件代表 Table 的屬性。 您可以使用 Columns 物件的 Add (String) 方法,將特定屬性新增至 Table 物件。 您可以使用 Table 物件的 Restrict (String) 方法來篩選特定屬性。 不過,某些屬性無法使用 Columns.Add 新增至 Table 物件,也無法使用 Restrict 方法進行篩選。 下表描述當您使用 Columns.AddRestrict 方法時,Table 物件是否支持屬性。

Property

若為 Columns.Add

針對限制

二進位屬性,例如 EntryID

透過內建或命名空間屬性支援。

不支援。 Outlook 會引發錯誤。

本文屬性,包括 BodyHTMLBody,以及這些屬性的命名空間表示法,包括 PR_RTF_COMPRESSED

Body 屬性支援的條件是,只有值的前 255 個字節會儲存在 Table 物件中。 不支援以 HTML 或 RTF 表示本文內容的其他屬性。 因為只會傳回 Body 的前 255 個字節,所以如果您想要以文字或 HTML 取得專案的完整本文內容,請使用 GetItemFromID (String、 Object) 方法中的專案 EntryID 來取得項目物件。 然後透過項目物件擷取 Body 的完整值。

篩選中只支援純文字顯示的 Body 屬性。 這表示必須在 DAV 搜尋中參考屬性,並找出 (DASL) 篩選為 urn:schemas:HTTP-mail:textdescription,而且您無法篩選本文中的任何 HTML 標記。 若要改善效能,請在篩選中使用內容索引器關鍵詞來比對本文中的字串。

計算機屬性,例如 AutoResolvedWinnerBodyFormat

不支援。

不支援。

多重值屬性,例如 CategoriesChildrenCompaniesVotingOptions

支援。

支援,前提是您可以使用命名空間表示法來建立 DASL 查詢。

傳回對象的屬性,例如 AttachmentsParentRecipientsRecurrencePatternUserProperties

不支援。

不支援。

下表列出無法使用 Columns.Add 新增至 Table 物件的已知無效屬性。 如果您嘗試從此清單新增屬性,Outlook 將會引發錯誤。

AutoResolvedWinner

BodyFormat

類別

公司

ContactNames

DLName

DownloadState

FlagIcon

HtmlBody

InternetCodePage

IsConflict

IsMarkedAsTask

MeetingWorkspaceURL

MemberCount

權限

PermissionService

RecurrenceState

ResponseState

Saved

寄件日期

已提交

TaskSubject

未讀取

VotingOptions

雖然某些計算屬性無法新增至數據表的數據行集,但下列程式代碼範例會因應這項限制。 GetToDoItems 會使用 DASL 查詢來限制出現在數據 中的專案。 如果計算屬性具有命名空間表示法,則會使用命名空間表示法來建立 DASL 查詢,限制 Table 物件傳回計算屬性之指定值的數據列。 GetToDoItems 會取得 [收件匣] 中的專案,其中 IsMarkedAsTask 屬性的值等於 true,然後將值指派給特定工作屬性,例如 TaskSubjectTaskDueDateTaskStartDateTaskCompletedDate。 最後,這些屬性會寫入接聽程式集合的追蹤接 程式。

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 GetToDoItems()
{
    // Obtain Inbox
    Outlook.Folder folder =
        Application.Session.GetDefaultFolder(
        Outlook.OlDefaultFolders.olFolderInbox)
        as Outlook.Folder;
    // DASL filter for IsMarkedAsTask
    string filter = "@SQL=" + "\"" +
        "http://schemas.microsoft.com/mapi/proptag/0x0E2B0003"
        + "\"" + " = 1";
    Outlook.Table table =
        folder.GetTable(filter,
        Outlook.OlTableContents.olUserItems);
    table.Columns.Add("TaskStartDate");
    table.Columns.Add("TaskDueDate");
    table.Columns.Add("TaskCompletedDate");
    // Use GUID/ID to represent TaskSubject
    table.Columns.Add(
        "http://schemas.microsoft.com/mapi/id/" +
        "{00062008-0000-0000-C000-000000000046}/85A4001E");
    while (!table.EndOfTable)
    {
        Outlook.Row nextRow = table.GetNextRow();
        StringBuilder sb = new StringBuilder();
        sb.AppendLine("Task Subject: " + nextRow[9]);
        sb.AppendLine("Start Date: "
            + nextRow["TaskStartDate"]);
        sb.AppendLine("Due Date: "
            + nextRow["TaskDueDate"]);
        sb.AppendLine("Completed Date: "
            + nextRow["TaskCompletedDate"]);
        sb.AppendLine();
        Debug.WriteLine(sb.ToString());
    }
}

另請參閱