VB.NET下载文件及显示进程

简单的下载

1.创建WebClient类,再输入要下载的资源url地址还有本地保存路径即可。

Dim DownloadClient As New Net.WebClient() 
DownloadClient.DownloadFile(yoururladdress,yourfileaddress)

2.使用 DownloadFile的方法下载文件,指定文件的下载地址和本地路径,和超时时间。

My.Computer.Network.DownloadFile(yoururladdress, yourfileaddress, False, 500)

具有进度提示的下载

以VS2015为编译环境,举例如下:

Imports System.Net
Public Class Main

    Dim DownloadClient As New WebClient

    Private Sub Form_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        AddHandler DownloadClient.DownloadProgressChanged, AddressOf ShowDownProgress 
        AddHandler DownloadClient.DownloadDataCompleted, AddressOf DownloadDataCompleted
    End Sub

    Private Sub Button_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button.Click
        DownLoadFiles()
    End Sub

    Private Sub DownLoadFiles()  
         DownloadClient.DownloadFileAsync(New Uri(yourlink), (yoursaveaddress))
    End Sub

    Private Sub ShowDownProgress(ByVal sender As Object, ByVal e As DownloadProgressChangedEventArgs)
        Invoke(New Action(Of Integer)(Sub(i) ProgressBar.Value = i), e.ProgressPercentage)
    End Sub

    Sub DownloadDataCompleted(ByVal sender As Object, ByVal e As System.ComponentModel.AsyncCompletedEventArgs)
        MessageBox.Show("下载成功!", "提示", MessageBoxButtons.OK)
    End Sub
End Class