Click here to Skip to main content
14,691,039 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi i wrote following code for get name of outlook inbox subfolders to combo box
public void LoadEmailFolderCombo(ToolStripComboBox nbFolder)
      {
          OutLook._Application outlookObj = new OutLook.Application();
          OutLook.MAPIFolder emailFolder = (OutLook.MAPIFolder)
           outlookObj.Session.GetDefaultFolder(OutLook.OlDefaultFolders.olFolderInbox);

          if (!nbFolder.Items.Contains("Default"))
          {
              nbFolder.Items.Add("Default");
          }
          foreach (OutLook.MAPIFolder subFolder in emailFolder.Folders)
          {
              if (!nbFolder.Items.Contains(subFolder.Name))
              {
                  nbFolder.Items.Add(subFolder.Name);
              }
          }
      }


but there is a problem it takes only names of folders inside the inbox folder but wont take names of folders in side the subfolders as example think that i have 1 subfolder kasun inside the inbox and inside kasun i have kasunmit it takes only kasun not kasunmit pls tell wht i am trying to is correct or is there any new way to do it
thank you
Posted
Updated 15-Jun-10 1:59am
v2

1 solution

A little recursion might help :
public void GetFoldersInFolder(OutLook.MAPIFolder folder)
   {
     foreach (OutLook.MAPIFolder subFolder in folder.Folders)
           {
               if (!nbFolder.Items.Contains(subFolder.Name))
               {
                   nbFolder.Items.Add(subFolder.Name);
                   GetFoldersInFolder(subFolder);
               }
           }
    }


Incorporate this in your "LoadEmailFolderCombo" method.

Cheers
   
Comments
Kasunmit 15-Jun-10 9:00am
   
thanx i ll try it ..

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900