'Check if Outlook MAPIFolder is visible?

When I iterate through all Outlook folders (in a C# Add-In) I see folder names like:

  • Yammer Root
  • Sync Issues
  • Subscriptions

These folders are not visible in Outlook. I like to check in my code if the folder is visible or not but I don't find a property like Hidden or Visible.

MAPIFolder folder has properties like:

  • folder.DefaultItemType
  • folder.Name

but not hidden.

How can I find out in my c# Add-In if folders are hidden or not?



Solution 1:[1]

You will need to read the PR_ATTR_HIDDEN MAPI property (DASL name http://schemas.microsoft.com/mapi/proptag/0x10F4000B). You can read it using MAPIFolder.PropertyAccessor.GetProperty.

You can see that (and other) property using OutlookSpy (I am its author) - click IMAPIFolder button.

Solution 2:[2]

At least on my machine I never retrieved a value for PR_ATTR_HIDDEN for all folders. I could not find out the reason although in OutlookSpy the value is true for the hidden folders.

Code:

        var rootFolder = outlook.Session.DefaultStore.GetRootFolder();
        foreach (Folder folder in rootFolder.Folders)
        {
            try
            {
                bool isHidden = folder.PropertyAccessor.GetProperty("http://schemas.microsoft.com/mapi/proptag/0x10F4000B");
                // never reach this line
            }
            catch (System.Exception ex)
            {
                // always exception: value is not available
            }
        }

My workaround: If you want to retrieve the folders as they are displayed in Outlook you can use PR_CONTAINER_CLASS_W and compare it with IPF.Note or IPF.Imap.

Sample:

        const string PR_CONTAINER_CLASS_W = "http://schemas.microsoft.com/mapi/proptag/0x3613001F";

        string containerClass = folder.PropertyAccessor.GetProperty(PR_CONTAINER_CLASS_W);
        bool isVisible = string.Equals(containerClass, "IPF.Note")|| string.Equals(containerClass, "IPF.Imap");

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Dmitry Streblechenko
Solution 2