Get Outlook folder details using LINQ RRS feed

  • Question

  • I wanted to get Outlook folder details(User Created Outlook Folder Names) using Linq query,There's no any error but expected result not achieved,

    Here is my code.

    private IEnumerable<MAPIFolder> GetAllFolders(Folders folders)
    foreach (MAPIFolder f in folders) {
        yield return f;
        foreach (var subfolder in GetAllFolders(f.Folders)) {
            yield return subfolder;

    Here is my button click event,

    private void button1_Click(object sender, EventArgs e)
     Microsoft.Office.Interop.Outlook.Application oApp  = new Microsoft.Office.Interop.Outlook.Application();
            Microsoft.Office.Interop.Outlook._NameSpace ns = (Microsoft.Office.Interop.Outlook._NameSpace)oApp.GetNamespace("MAPI"); 
          foreach (var f in GetAllFolders(ns.Folders)) {
        //if (f == DELETE_FOLDER) continue;
        if (f.DefaultItemType == OlItemType.olMailItem) {
           string ff = f.Name;//here i tried to get folder name,but it doen't return foldernames

    I wanted to get User Created Folder names.. this is my first Outlook AddIn,If you can provide answer with's help me..

    Tuesday, February 12, 2013 4:53 PM


  • what exactly does not work?  what value do you expect to get in folder.Name? and please remember that below .net object there are COM objects and RPC connections to exchange server (if you are using Exchange mailbox) - so most efficient way of handling those pobjects is to iterate through for() and release objects as soon as possible.
    Tuesday, February 12, 2013 6:38 PM