Click here to Skip to main content
15,887,746 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am using this code to get the list of email folders :

VB
Class emailFolder
          Public Property Title As String
      End Class

        Public Shared Function GetFolders() As List(Of emailFolder)
          Dim folder = New List(Of emailFolder)
          Dim foldername = client.Folders
          For Each parentFolder In foldername
              Dim parentPath = parentFolder.Path
              If parentFolder.HasChildren Then
                  Dim subfolders = parentFolder.SubFolders
                  For Each subfolder In subfolders
                      Dim subPath = subfolder.Path
                      folder.Add(New emailFolder With {.Title = parentFolder.Name})
                  Next
              End If
          Next
          Return folder
      End Function

      Public sub btn_click handles Button1.click

      ListView.ItemSource=GetFolders


I dunno what is wrong with my code but the items i get in the listview(i'm in wpf by the way) look like this :

MyApplication++emailfolder
MyApplication++emailfolder
MyApplication++emailfolder
MyApplication++emailfolder

What am i doing wrong ?

What I have tried:

What i've tried is already mentioned in the post above
Posted
Updated 6-Feb-18 22:32pm

1 solution

You have an inner loop (foreach subfolder In subfolders) but create the name always from the parentFolder.

So it should be (untested)
VB
' Optionally add parent folder always here
'folder.Add(New emailFolder With {.Title = parentFolder.Name})
If parentFolder.HasChildren Then
    Dim subfolders = parentFolder.SubFolders
    For Each subfolder In subfolders
        folder.Add(New emailFolder With {.Title = subFolder.Name})
    Next
' If parent folder has not been added above, do it here.
Else
    folder.Add(New emailFolder With {.Title = parentFolder.Name})
End If
 
Share this answer
 
Comments
Member 13336882 7-Feb-18 6:26am    
same result
Member 13336882 7-Feb-18 6:28am    
i don't get it...can u try the code urself and see if the result is the same
Jochen Arndt 7-Feb-18 8:06am    
Sorry, I have VB.Net not installed.

You have used parentFolder.Name instead of subFolder.Name to add the name to the list. So all child folder names added to the list will be identical. You have also not added folder names for folders that does not have childs.

But your output "MyApplication++emailfolder" indicates that there is also something else wrong (you did not get the folder names).

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