Click here to Skip to main content
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 1:41am
Edited 15-Jun-10 1:59am
Henry Minute223.9K
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 George Jonsson 215
1 Kornfeld Eliyahu Peter 169
2 Zoltán Zörgő 139
3 PIEBALDconsult 130
4 OriginalGriff 120
0 OriginalGriff 6,165
1 DamithSL 4,658
2 Maciej Los 4,107
3 Kornfeld Eliyahu Peter 3,649
4 Sergey Alexandrovich Kryukov 3,342


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