Click here to Skip to main content
11,706,639 members (35,457 online)
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C#3.0 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
Edited 15-Jun-10 0:59am
Henry Minute224.6K
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 at 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
0 OriginalGriff 202
1 Sergey Alexandrovich Kryukov 135
2 chainerlt 110
3 Mika Wendelius 80
4 ppolymorphe 71
0 OriginalGriff 9,190
1 Sergey Alexandrovich Kryukov 8,407
2 CPallini 5,189
3 Maciej Los 4,756
4 Mika Wendelius 3,686


Advertise | Privacy | Mobile
Web03 | 2.8.150819.1 | Last Updated 15 Jun 2010
Copyright © CodeProject, 1999-2015
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