I\'m looking for some code (C# or VB.NET preferred) to iterate through all folders in an Outlook mailbox and return the names of those folders. I\'m not looking to pop up t
I prefer a more LINQ friendly approach:
private IEnumerable GetAllFolders(Folders folders)
{
foreach (MAPIFolder f in folders) {
yield return f;
foreach (var subfolder in GetAllFolders(f.Folders)) {
yield return subfolder;
}
}
}
Then you can peruse the folders any way like. For example:
private IEnumerable GetAllEmail(NameSpace ns)
{
foreach (var f in GetAllFolders(ns.Folders)) {
if (f == DELETE_FOLDER) continue;
if (f.DefaultItemType == OlItemType.olMailItem) {
// Party!
}
}
}