Export (0) Print
Expand All
This topic has not yet been rated - Rate this topic

How to: Filter and Display Multivalued Properties When Enumerating Items in a Folder

This example shows how to filter and display multivalued properties while enumerating items in a folder.

Programming Applications for Office Outlook 2007

The following code example is an excerpt from Programming Applications for Microsoft Office Outlook 2007, from Microsoft Press (ISBN 9780735622494, copyright Microsoft Press 2007, all rights reserved).

Buy this book

Sample chapters

The Table object represents a set of item data from a Folder or Search object. When a binary, date, or multivalued property is first added to a Table object, the way the property is referenced affects its type and format. Because built-in name references sometimes return a different column value than a namespace reference, you should determine whether the property is referenced by its explicit built-in name (if it has one), or by namespace (regardless of the existence of an explicit built-in name). The following table shows the difference in the property value representation (in terms of type and format) per original property type.

Type

Return type if the specified property uses a built-in name

Return type if the specified property uses a namespace

Binary (PT_BINARY)

String

Byte array

Date (PT_SYSTIME)

Local DateTime

UTC DateTime

Multivalued (also known as keyword type) such as Categories property (PT_MV_STRING8)

String that contains comma-separated values

One-dimensional array that contains one element for each keyword

The following code example illustrates how to add a MAPI string namespace property to the Table object and how multivalued properties affect the values returned in a Column object. The TableMultiValuedProperties procedure filters the Table object for rows where the Categories property is not a null reference. The Categories property is represented by a property that uses the MAPI string namespace. A DAV Searching and Locating (DASL) filter is constructed for items that have categories (the actual filter returns categories that do not have a null reference). A Categories column is then added to the Table object by concatenating the type specifier, 0000001f, with the categoriesProperty constant. Finally, the Column object that represents the Categories property contains a one-dimensional string array where each element of the array represents a category assigned to the item. Both the item’s Categories and Subject properties are written to the trace listeners of the Listeners collection.

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");
    }
}

Other resources

Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2014 Microsoft. All rights reserved.