How to: Enumerate Hidden Items in a Folder

Office 2013 and later

This example shows how to find and enumerate hidden 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

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 =
        as Outlook.Folder;
    // Call GetTable with OlTableContents.olHiddenItems
    Outlook.Table table =
    while (!table.EndOfTable)
        Outlook.Row nextRow = table.GetNextRow();
        // Test for null subject
        if (nextRow["Subject"] == null)
            Debug.WriteLine(nextRow["Subject"] + " "
                + nextRow["MessageClass"]);

Other resources