当前正在使用FTPwebrequest在vb.net中的FTP客户端上工作。我已经成功完成了它的工作,它正在上载和检索所有文件并将其显示在Listview中。我现在关心的是对列表视图中显示的远程目录中的项目进行排序/排列,以首先显示新添加的项目,依此类推。
我已经尝试过在线研究,但无济于事。仍在寻找。
这是用于显示目录内容的代码
Private Sub SampleProcedure1()
Try
'Create an FTP web request
Dim ftpwebrequest As FtpWebRequest = DirectCast(WebRequest.Create("ftp://" & settings.txtserveraddress.Text & "/" & settings.foldername.Text & "/"), FtpWebRequest)
'Set properties
With ftpwebrequest
'ftp server username and password
.Credentials = New NetworkCredential(settings.txtserverusername.Text, settings.txtserverpassword.Text)
'set the method to download
.Method = WebRequestMethods.Ftp.ListDirectory
'upload timeout to 100 seconds
.Timeout = "100000"
End With
Dim ftpwebres As FtpWebResponse = CType(ftpwebrequest.GetResponse(), FtpWebResponse)
Dim ftpstreamreader As StreamReader = New StreamReader(ftpwebres.GetResponseStream())
'clear list of files
ftpclient.lstfiles.Items.Clear()
'start loading files from an FTP server into list
While (ftpstreamreader.Peek() > -1)
ftpclient.lstfiles.Items.Add(ftpstreamreader.ReadLine())
End While
ftpstreamreader.Close()
ftpwebres.Close()
Catch ex As Exception
ftpclient.Cursor = Cursors.Default
ftpclient.NotifyIcon1.ShowBalloonTip(1000, "Test FTP Client", ex.Message, ToolTipIcon.Info)
End Try
End Sub
Listview应该首先根据最新添加/上传的项目显示/排序。是的,它不是向后排序,而是按字母顺序排序。