Click here to Skip to main content
14,668,181 members
Rate this:
Please Sign up or sign in to vote.
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 0:59am
v2

1 solution

Rate this:
Please Sign up or sign in to vote.

Solution 1

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, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100