2014-09-26 98 views
0

我在VB中創建一個項目,它有一個文件下載器,它可以很好地處理.txt或圖像等文件,但是當我嘗試下載一個.exe文件時.exe會變成損壞的文件,我的意思是,該程序只下載1 KB的文件,不可能執行它。VB .exe文件下載

我使用這個代碼:


My.Computer.Network.DownloadFile(
    "http://www.web.domain/Archive.exe", 
    "C:\Archive.exe") 

我在VS 2013版本的工作。

+0

定義損壞? – Psychemaster 2014-09-26 08:16:39

+0

編輯,對不起:D – 2014-09-26 11:38:14

+0

由於很多原因,大多數Web服務器阻止下載EXE文件(通過http)。我認爲DownloadFile總是首先創建一個1KB文件,以確保您可以寫入所需的位置。你有控制網絡服務器嗎? – Steve 2014-09-30 16:39:28

回答

0

YAY !!!我找到了一個解決方案:

那裏是^^。謝謝你的答案。


Private Sub download_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles  Download.Click 
    Download.Enabled = False 
    httpclient = New WebClient 
    AddHandler httpclient.DownloadFileCompleted, AddressOf Downloaded 

    httpclient.DownloadFileAsync(New Uri("https://www.dropbox.com/s/2ch4prhn063hmxs/vanilla.exe?dl=1"), ("C:\BarberLand\downloads\Vanilla\vanilla.exe")) 
End Sub 

Private Sub dpc(ByVal sender As Object, ByVal e As System.Net.DownloadProgressChangedEventArgs) Handles httpclient.DownloadProgressChanged 
    porcentaje.Text = e.ProgressPercentage 
End Sub 

Private Sub Downloaded() 
    'Comprueba si el fichero se ha descargado completamente. 
    If System.IO.File.Exists("C:\BarberLand\downloads\Vanilla\vanilla.exe") = True Then 

     Process.Start("C:\BarberLand\downloads\Vanilla\vanilla.exe") 
     Me.Close() 
    Else 
     MsgBox("El fichero no existe, pruebe con otra versión o si piensa que es un error, contácte con el administrador", 64, "Open") 
    End If 

End Sub