无法使用IMAPX VB.NET获取电子邮件文件夹名称 [英] Can't get email folder name using IMAPX VB.NET
本文介绍了无法使用IMAPX VB.NET获取电子邮件文件夹名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用此代码获取电子邮件文件夹列表:
类 emailFolder
公共 属性标题正如 字符串
结束 类
公开 共享 函数 GetFolders()作为列表( emailFolder)
< span class =code-keyword> Dim folder = 新列表( emailFolder)
Dim foldername = client.Folders
对于 每个 p arentFolder 在 foldername
Dim parentPath = parentFolder.Path
如果 parentFolder.HasChildren 那么
Dim 子文件夹= parentFolder .SubFolders
对于 每个子文件夹在子文件夹
Dim subPath = subfolder.Path
folder.Add( New emailFolder 使用 {.Title = parentFolder.Name})
下一步
结束 如果
下一步
返回文件夹
结束 功能
公开 sub btn_click handle Button1.click
ListView.ItemSource = GetFolders
我不知道什么是我的代码错了,但我在listview中得到的项目(顺便说一句,我在wpf中)看起来像这样:
MyApplication ++ emailfolder
MyApplication ++ emailfolder
MyApplication ++ emailfolder
MyApplication ++ emailfolder
什么是我做错了吗?
我尝试了什么:
我是什么在上面的帖子中已经提到过试过
解决方案
你有一个内循环(foreach子文件夹在子文件夹中
)但总是从。创建名称parentFolder
。
所以应该是(未经测试)
可选择在此处始终添加父文件夹
' folder.Add(带有{.Title = parentFolder.Name}的新emailFolder)
如果 parentFolder.HasChildren 那么
Dim 子文件夹= parentFolder.SubFolders
对于 每个子文件夹在子文件夹中
folder.Add(新 emailFolder 使用 {.Title = subFolder.Name})
下一步
' 如果父文件夹有上面没有添加,请在这里做。
其他
folder.Add(新 emailFolder 使用 {.Title = parentFolder.Name})
结束 如果< /跨度>
I am using this code to get the list of email folders :
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
解决方案
You have an inner loop (foreach subfolder In subfolders
) but create the name always from theparentFolder
.
So it should be (untested)
' 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
这篇关于无法使用IMAPX VB.NET获取电子邮件文件夹名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文