Enumerate hidden items in a folder

This example shows how to find and enumerate hidden items in a folder.

Example

Note

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

One feature of the Table object, which represents a set of items in a folder, is that it may have hidden items. To return hidden items in a folder, set the TableContents parameter in the GetTable(Object, Object) method of the MAPIFolder object to olHiddenItems. In the following code example, TableForInboxHiddenItems obtains the hidden items of an Inbox folder, and writes the values of the Subject and MessageClass properties for each hidden item 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 TableForInboxHiddenItems()
{
    // Inbox
    Outlook.Folder folder =
        Application.Session.GetDefaultFolder(
        Outlook.OlDefaultFolders.olFolderInbox)
        as Outlook.Folder;
    // Call GetTable with OlTableContents.olHiddenItems
    Outlook.Table table =
        folder.GetTable("",
        Outlook.OlTableContents.olHiddenItems);
    while (!table.EndOfTable)
    {
        Outlook.Row nextRow = table.GetNextRow();
        // Test for null subject
        if (nextRow["Subject"] == null)
        {
            Debug.WriteLine(nextRow["MessageClass"]);
        }
        else
        {
            Debug.WriteLine(nextRow["Subject"] + " "
                + nextRow["MessageClass"]);
        }
    }
}

See also

-Search and filter