Reputation: 2787
When I iterate through all Outlook folders (in a C# Add-In) I see folder names like:
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:
but not hidden.
How can I find out in my c# Add-In if folders are hidden or not?
Upvotes: 1
Views: 824
Reputation: 66341
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.
Upvotes: 2
Reputation: 33
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");
Upvotes: 0