Click here to Skip to main content
12,400,183 members (55,204 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: C#3.0 C# Outlook
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 15-Jun-10 0:41am
Updated 15-Jun-10 0:59am
Henry Minute225.2K
v2

1 solution

Rate this: bad
 
good
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
  Permalink  
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)

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web02 | 2.8.160721.1 | Last Updated 15 Jun 2010
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100