共用方式為


搜尋資料夾中專案的附件,以取得確切的片語

此範例會搜尋 [收件匣] 中專案附件中的確切搜尋字元串 “office”。

範例

此程式代碼範例會使用 DAV 搜尋和尋找 (DASL) 語法來指定查詢。 若要建構篩選條件,程式代碼範例會先檢查預設存放區中是否已啟用立即搜尋,以決定是否要使用 ci_phrasematch 關鍵詞,以取得與任何附件中 “office” 完全相符的詞組。 然後,此範例會將篩選套用至收件匣上的 GetTable 方法,並在 Table 物件中取得結果。 程式代碼範例接著會顯示 Table 中每個傳回專案的主旨。

程式代碼範例會使用命名空間表示https://schemas.microsoft.com/mapi/proptag/0x0EA5001E法 ,指定專案的 Attachments 屬性。 使用 ci_phrasematch 關鍵詞的語法為:

<PropertySchemaName> ci_phrasematch <ComparisonString>

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 Imports or using statement must not occur directly before the functions in the code example but must be added before the public Class declaration. The following lines of code show how to do the import and assignment in Visual Basic and C#.

Imports Outlook = Microsoft.Office.Interop.Outlook
using Outlook = Microsoft.Office.Interop.Outlook;
Private Sub DemoSearchAttachments()
    Dim filter As String
    Const PR_SEARCH_ATTACHMENTS As String = _
        "http://schemas.microsoft.com/mapi/proptag/0x0EA5001E"
    If (Application.Session.DefaultStore.IsInstantSearchEnabled) Then
        filter = "@SQL=" & Chr(34) _
            & PR_SEARCH_ATTACHMENTS & Chr(34) _
            & " ci_phrasematch 'office'"
        Dim table As Outlook.Table = _
            Application.Session.GetDefaultFolder( _
            Outlook.OlDefaultFolders.olFolderInbox).GetTable( _
            filter, Outlook.OlTableContents.olUserItems)
        While Not (table.EndOfTable)
            Dim row As Outlook.Row = table.GetNextRow()
            Debug.WriteLine(row("Subject"))
        End While
    End If
End Sub
private void DemoSearchAttachments()
{
    string filter;
    const string PR_SEARCH_ATTACHMENTS =
        "http://schemas.microsoft.com/mapi/proptag/0x0EA5001E";
    if (Application.Session.DefaultStore.IsInstantSearchEnabled)
    {
        filter = "@SQL=" + "\""
            + PR_SEARCH_ATTACHMENTS + "\""
            + " ci_phrasematch 'office'";
        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"]);
        }
    }
}

另請參閱