共用方式為


篩選和顯示上個月修改的收件匣專案

此範例示範如何篩選和顯示上個月修改過的收件匣專案。

範例

注意事項

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

DAV 搜尋和尋找 (DASL) 查詢語言是以 Outlook 中 DASL 的 Microsoft Exchange 實作為基礎。 它可以用來傳回資料夾資料中專案層級搜尋的屬性型結果,例如 Table 物件所代表的結果。 DASL 篩選條件支援字串比較,包括等價、前置詞、片語和子字串比對,方法是使用等 (=) 運算符。 您可以使用 DASL 查詢來執行日期時間比較和篩選。

由於 DASL 查詢一律會在國際標準時間 (UTC) 中執行 DateTime 比較,因此如果您想要讓查詢正常運作,就必須將本地時間值轉換成 UTC。 您也必須將 DateTime 值轉換成字串表示,因為 DASL 篩選條件支援字串比較。 您可以透過兩種方式進行 DateTime 轉換:使用 LocalTimeToUTC (Object) Row 物件的 方法,或使用 Outlook DateTime 宏進行轉換。

下列程式代碼行示範如何使用 LocalTimeToUTC 方法,將 LastModificationTime 屬性的值轉換 (這是所有 Item 物件中的預設數據行,) UTC。

DateTime modified = nextRow.LocalTimeUTC(“LastModificationTime”);

下表列出您可以用來傳回篩選字串的 DateTime 宏,這些字串會比較指定 DateTime 屬性的值與 UTC 中指定的相對日期或日期範圍。 SchemaName 屬性值代表命名空間所參考的任何有效 DateTime 屬性。

巨集

語法

描述

今天

%today (“SchemaName”) %

限制 SchemaName 屬性值等於今天的專案。

明天

%tomorrow (“SchemaName”) %

限制 SchemaName 屬性值等於明天的專案。

昨天

%昨天 (「SchemaName」) %

限制 SchemaName 屬性值等於昨天的專案。

next7days

%next7days (“SchemaName”) %

限制 SchemaName 屬性值在相當於接下來七天範圍內的專案。

last7days

%last7days (“SchemaName”) %

限制具有 SchemaName 屬性值的專案,其範圍相當於過去七天。

nextweek

%nextweek (“SchemaName”) %

限制 SchemaName 屬性值在相當於下一周範圍內的專案。

thisweek

%thisweek (“SchemaName”) %

限制 SchemaName 屬性值在相當於本周範圍內的專案。

lastweek

%lastweek (“SchemaName”) %

限制 SchemaName 屬性值在相當於上周範圍內的專案。

nextmonth

%nextmonth (“SchemaName”) %

限制在相當於下個月範圍內具有SchemaName屬性值的專案。

thismonth

%thismonth (“SchemaName”) %

限制具有 SchemaName 屬性值且範圍相當於這個月份的專案。

lastmonth

%lastmonth (“SchemaName”) %

限制 SchemaName 屬性值在相當於上個月範圍內的專案。

在下列範例中,DemoDASLDateMacro 會建立 DASL 查詢,此查詢會使用 lastmonthDateTime 宏來篩選使用者的 [收件匣] 中上個月修改過的專案。 然後,它會使用該篩選條件建立 Table 對象,並列舉並顯示受限制 Table 物件中的數據列。

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 DemoDASLDateMacro()
{
    string filter = "@SQL=" + "%lastmonth(" + "\"" +
        "DAV:getlastmodified" + "\"" + ")%";
    Outlook.Table table = Application.Session.GetDefaultFolder(
        Outlook.OlDefaultFolders.olFolderInbox).GetTable(
        filter, Outlook.OlTableContents.olUserItems);
    while (!table.EndOfTable)
    {
        Outlook.Row row = table.GetNextRow();
        Debug.WriteLine(row["Subject"]);
    }
}

另請參閱