Navigating across Outlook 2003 Folders from C# program

M

michel.kowalczyk

Hi,

Coudn't figure this by my own:(
How to print to the console all outlook folders and mail subjects. I
was able to write a piece of code that prints the names of the main
folders but I don't know how to print subfolders and mails subjects.
Anyone ?? help.



My outlook foldertree looks like that:
Personal Files
Drafts
Inbox
Junk E-mail
Outbox
Sent Items
Some Folder
Nested Folder
Search Folders
Folders 2
Deleted Items
Hello
Search Folders


My code:

using Outlook = Microsoft.Office.Interop.Outlook;

Outlook.Application oApp = new Outlook.Application();
Outlook.NameSpace oNS = oApp.GetNamespace("mapi");
oNS.Logon(Missing.Value, Missing.Value, false, true);

Outlook.MAPIFolder oIFolder = oNS.Folders.GetFirst();
Console.WriteLine(oIFolder.Name);
int nFolderCount = oNS.Folders.Count;
for (int p=1; p < nFolderCount; p++)
{
oIFolder = oNS.Folders.GetNext();
Console.WriteLine(oIFolder.Name);
}

TIA
Michal

p.s.

I use Outlook 2003
Microsoft Visual C# 2005 Express Edition
Microsoft XP Pro
 
S

Sue Mosher [MVP-Outlook]

I can't help you with the exact code since I don't do C#, but each folder has a Folders collection, so what you need to do is write a recursive procedure that takes a MAPIFolder as its argument, then iterates that MAPIFolder's Folders collection. For each MAPIFolder in the collection, call the recursive procedure to process the subfolders.

--
Sue Mosher, Outlook MVP
Author of Configuring Microsoft Outlook 2003

and Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top