Dim ftp As New FtpClient
If Network.Ping("X.X.X.X", 1000) = False Then
ftp.Host = "X.X.X.X"
Else
ftp.Host = "X.X.X.X"
End If
ftp.Account = "X"
ftp.Password = "X"
Dim lvw As WinForm.ListView = Forms("需求文件上传FTP").Controls("ListView3")
lvw.Rows.Clear
lvw.Images.Clear
lvw.Images.LargeSize = New size(32, 32)
Dim ics As String() = {"swf", "accdb", "mdb", "psd", "png", "xls", "xlsx", "bmp", "rar", "jpg", "gif", "doc", "docx", "zip", "pdf", "txt", "ppt", "exe", "bin", "map", "other"} '定义扩展名数组
Dim kzms As String = "swf accdb mdb psd png xls xlsx bmp rar jpg gif doc docx zip pdf txt ppt exe bin map" '定义已知扩展名的文本串
For Each ic As String In ics
lvw.Images.AddImage(ic, ic & ".png", ic & ".png") '向listview里添加图标
Next
'==============================以上是设置listview的代码============================
'==============================以下是生成listview的代码============================
Dim sts As List(Of String) = ftp.GetFileList(vars("ljwjj"))
If sts.Count > 0 Then '若有文件
For Each st As String In sts
Dim r As WinForm.ListViewRow = lvw.Rows.Add '增加一行
Dim Dot As Integer = st.LastIndexOf(".") '定义.的位置
Dim kzm As String = st.SubString(Dot + 1) '获取扩展名
r.text = st
If kzms.Contains(kzm) = True Then '若为已知扩展名
r.ImageKey = kzm '指定行的图标键值
Else
r.ImageKey = "other"
End If
Next
End If
'上传带扩展名的文件都正常显示,但上传不带扩展名的文件,没显示。
ftp.Close