11月 042013
 

今回はVB Net開発環境でWebClientに用いてファイルのダウンロード方法を説明する
[vb]
Private WithEvents myWebclient As Net.WebClient
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim remoteUri As String = "https://51flya.com"
Dim fileName As String = Application.StartupPath + "send.ini"
myWebclient = New Net.WebClient()
myWebclient.DownloadFileAsync(New Uri(remoteUri), fileName)
End Sub

Private Sub myWebclient_DownloadFileCompleted(ByVal sender As Object, ByVal e As System.ComponentModel.AsyncCompletedEventArgs) Handles myWebclient.DownloadFileCompleted
MsgBox("完了")
End Sub

Private Sub myWebclient_DownloadProgressChanged(ByVal sender As Object, ByVal e As System.Net.DownloadProgressChangedEventArgs) Handles myWebclient.DownloadProgressChanged

‘e.BytesReceivedはダウンロード済みのサイズbytes

‘e.TotalBytesToReceiveは全部のサイズ

‘ e.ProgressPercentage 現在のパセント

End Sub
[/vb]