2017-07-12 16 views
0

私のコードでは、Webサイトからファイルをダウンロードして、FolderBrowserDialogで選択したディレクトリに保存します。 ' Download the files If My.Computer.Network.IsAvailable Then Try wClient.DownloadFile(New Uri("DOWNLOAD LINK"), FolderBrowserDialog1.SelectedPath & "FILENAME.123") wClient.DownloadFile(New Uri("DOWNLOAD LINK"), FolderBrowserDialog1.SelectedPath & "FileName.123) wClient.DownloadFile(New Uri("Download LINK"), FolderBrowserDialog1.SelectedPath & "FileName.123") Catch ex As Exception MessageBox.Show(ex.Message) End TryWebclient.DownloadFile to Folderbrowser.Selectedpath

答えて

0

私はあなたのために書いたサンプルコードを用意しています。 最初にwClientWebClientEventsと宣言しているので、ファイルのダウンロード時に何が起きるかをトリガーすることができます。

VLC Media Playerを例としてダウンロードしましたが、ニーズに合わせて変更しました。注記これは、ボタンクリックイベントで行いました。

Imports System.ComponentModel 
Imports System.Net 
Public Class Form1 
Private WithEvents wClient As New WebClient() 
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click 

    Dim FolderBrowserDiaglog1 As New FolderBrowserDialog() 
    Dim folderPath As String = "" 
    Dim fileName As String = "vlc.exe" 

    Dim downloadFile As String = "https://get.videolan.org/vlc/2.2.6/win32/vlc-2.2.6-win32.exe" ''VLC MEDIA PLAYER 
    If FolderBrowserDiaglog1.ShowDialog() = DialogResult.OK Then 
     folderPath = FolderBrowserDiaglog1.SelectedPath 
    End If 
    If My.Computer.Network.IsAvailable Then 
     Dim combinePath As String = System.IO.Path.Combine(folderPath, fileName) 
     wClient.DownloadFileAsync(New Uri(downloadFile), combinePath) 
    End If 
End Sub 

Private Sub wClient_DownloadFileCompleted(sender As Object, e As AsyncCompletedEventArgs) Handles wClient.DownloadFileCompleted 
    MessageBox.Show("File Downloaded") 
End Sub 
End Class 


wClientのイベントリストで見てくださいと、そのような私は、ファイルがダウンロードされた後、メッセージボックスを表示している作った一人としてavalibleている多くのオプションを参照してください。

Webクライアントイベントhttps://msdn.microsoft.com/en-us/library/system.net.webclient_events(v=vs.110).aspx