将带有 FTP 目录列表的 StreamReader 内容添加到 VB.NET 中的列表框?
这是我到目前为止的代码,
Dim listRequest As FtpWebRequest = WebRequest.Create("ftp://ftpserver.com/folder/")
listRequest.Credentials = New NetworkCredential(ftp_user, ftp_pass)
listRequest.Method = WebRequestMethods.Ftp.ListDirectory
Dim listResponse As FtpWebResponse = listRequest.GetResponse()
Dim reader As StreamReader = New StreamReader(listResponse.GetResponseStream())
ListBox1.Items.AddRange(reader.ReadToEnd())
MessageBox.Show(reader.ReadToEnd())
我对如何将 reader.ReadToEnd 的内容放入 ListBox 中感到非常困惑。如果有人可以帮助我解决这个问题,我将不胜感激。
This is the code I have so far
Dim listRequest As FtpWebRequest = WebRequest.Create("ftp://ftpserver.com/folder/")
listRequest.Credentials = New NetworkCredential(ftp_user, ftp_pass)
listRequest.Method = WebRequestMethods.Ftp.ListDirectory
Dim listResponse As FtpWebResponse = listRequest.GetResponse()
Dim reader As StreamReader = New StreamReader(listResponse.GetResponseStream())
ListBox1.Items.AddRange(reader.ReadToEnd())
MessageBox.Show(reader.ReadToEnd())
I am very confused on how I can put the contents of the reader.ReadToEnd
in a ListBox
. If anyone can assist me with this issue it would be greatly appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用
逐行读取流StreamReader.ReadLine
如果处理大量文件时的性能不是问题,以下低效但简短的代码也可以实现相同的效果:
请注意,您应该在后台线程上执行网络操作,但是这是一个单独的 问题。
Read the stream line-by-line using
StreamReader.ReadLine
If performance when dealing with huge amount of files is not a concern, the following inefficient but short code will do the same:
Note that you should be doing network operations on a background thread, but that's for a separate question.