Filter and display computed properties when enumerating items in a folder

This example shows how to filter and display computed properties when enumerating items in a folder.

Example

Note

The following code example is an excerpt from Programming Applications for Microsoft Office Outlook 2007.

The Table object represents a set of item data from a Folder or Search object. The Row object represents rows of data in a Table. The Columns object represents properties of the Table. You can add certain properties to the Table object by using the Add(String) method of the Columns object. You can filter certain properties by using the Restrict(String) method of the Table object. However, some properties cannot be added to the Table object by using Columns.Add, nor can they be filtered by using the Restrict method. The following table describes whether properties are supported for the Table object when you use the Columns.Add or Restrict method.

Property

For Columns.Add

For Restrict

Binary properties such as EntryID.

Supported via built-in or namespace property.

Not supported. Outlook will raise an error.

Body properties, including Body and HTMLBody, and namespace representation of those properties, including PR_RTF_COMPRESSED.

The Body property is supported with a condition that only the first 255 bytes of the value are stored in a Table object. Other properties that represent the body content in HTML or RTF are not supported. Because only the first 255 bytes of Body are returned, if you want to obtain the full body content of an item in text or HTML, use the item’s EntryID in the GetItemFromID(String, Object) method to obtain the item object. Then retrieve the full value of Body through the item object.

Only the Body property represented in text is supported in a filter. This means that the property must be referenced in a DAV Searching and Locating (DASL) filter as urn:schemas:http-mail:textdescription, and you cannot filter on any HTML tags in the body. To improve performance, use context indexer keywords in the filter to match strings in the body.

Computer properties, such as AutoResolvedWinner and BodyFormat.

Not supported.

Not supported.

Multivalued properties, such as Categories, Children, Companies, and VotingOptions.

Supported.

Supported, provided that you can create a DASL query by using the namespace representation.

Properties that return an object, such as Attachments, Parent, Recipients, RecurrencePattern, and UserProperties.

Not supported.

Not supported.

The following table lists known invalid properties that cannot be added to the Table object by using Columns.Add. If you attempt to add a property from this list, Outlook will raise an error.

AutoResolvedWinner

BodyFormat

Class

Companies

ContactNames

DLName

DownloadState

FlagIcon

HtmlBody

InternetCodePage

IsConflict

IsMarkedAsTask

MeetingWorkspaceURL

MemberCount

Permission

PermissionService

RecurrenceState

ResponseState

Saved

Sent

Submitted

TaskSubject

Unread

VotingOptions

Although some computed properties cannot be added to the column set for a table, the following code example works around this limitation. GetToDoItems uses a DASL query to restrict the items that appear in the Table. If the computed property has a namespace representation, the namespace representation is used to create a DASL query that restricts the Table object to return rows for a specified value of the computed property. GetToDoItems gets items in the Inbox where the value of the IsMarkedAsTask property is equal to true, and then assigns values to certain task properties such as TaskSubject, TaskDueDate, TaskStartDate, and TaskCompletedDate. Finally, those 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 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());
    }
}

See also