如何解决一一下载datagridview中列出的多个文件vb.net代码
Vb.net 工作室对我来说比较陌生(作为我有时间的爱好),所以我需要一些帮助。简单地下载单个文件很容易我通过以下代码来做到这一点。
Try
' Make a WebClient.
Dim web_client As WebClient = New WebClient
' Download the file.
web_client.DownloadFile("TargetURLSite/MyFolder/" & "MyFile.exe",(Application.StartupPath & "\Plugins\" & MyFile.exe))
Catch ex As Exception
MessageBox.Show(ex.Message,"Download Error",MessageBoxButtons.OK,MessageBoxIcon.Exclamation)
End Try
简单易行...
但我现在有一个 DataGridView 列,其中包含我要下载的文件的文件名。我以为我可以使用 for each 语句从 DataGridView 的第一列中获取目标文件名,并为每个目标文件逐个执行下载功能,但它似乎不起作用我相信这是因为Web 客户端在继续处理下一次下载之前,自己仍然在处理每次下载,这让 Web 客户端感到困惑。
For rowIndex = 0 To DataGridView1.RowCount - 1
'MsgBox("This cell is " & (DataGridView1.Rows(rowIndex).Cells("AppCol").Value.ToString))
Dim TargetApplication As String = (DataGridView1.Rows(rowIndex).Cells("AppCol").Value.ToString)
If My.Computer.FileSystem.FileExists(Application.StartupPath & "\Plugins\" & TargetApplication) Then
'File exists do nothing...
Else
'File dose not exist download to Plugins directory...
Try
' Make a WebClient.
Dim web_client As WebClient = New WebClient
' Download the file.
web_client.DownloadFile("TargetURLSite/MyFolder/" & TargetApplication,(Application.StartupPath & "\Plugins\" & TargetApplication))
Catch ex As Exception
MessageBox.Show(ex.Message,MessageBoxIcon.Exclamation)
End Try
End If
Next
我该如何解决这个问题?我对 vb.net 的了解有限。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。