问题描述
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 (将#修改为@)