Vb.net WebClient.DownloadFileAsync不适用于xp和8.1

时间:2014-09-29 23:41:23

标签: vb.net windows-xp

您在vb.net中创建了一个更新功能,可以在准备下载新更新时通知我的用户

所以这一切都适用于win 8和7但是当我尝试在xp和8.1上运行它时它只是完成下载但不下载任何文件:s

这是我的代码:

Imports System.Net

Public Class Form5
    Private Sub LogInButton1_Click(sender As Object, e As EventArgs) Handles LogInButton1.Click
        Dim client As WebClient = New WebClient
        AddHandler client.DownloadProgressChanged, AddressOf client_ProgressChanged
        AddHandler client.DownloadFileCompleted, AddressOf client_DownloadCompleted
        client.DownloadFileAsync(New Uri("FILE the download"), "C:\users\" & System.Environment.UserName & _
                                 "\AppData\Local\Software_update.exe")
        LogInButton1.Text = "Download in Progress"
        LogInButton1.Enabled = False
    End Sub

    Private Sub client_ProgressChanged(ByVal sender As Object, ByVal e As DownloadProgressChangedEventArgs)
        Dim bytesIn As Double = Double.Parse(e.BytesReceived.ToString())
        Dim totalBytes As Double = Double.Parse(e.TotalBytesToReceive.ToString())
        Dim percentage As Double = bytesIn / totalBytes * 100

        LogInProgressBar1.Value = Int32.Parse(Math.Truncate(percentage).ToString())
    End Sub

    Private Sub client_DownloadCompleted(ByVal sender As Object, ByVal e As System.ComponentModel.AsyncCompletedEventArgs)
        MessageBox.Show("Download Complete please restart the app ")
        LogInButton1.Text = "Download Complete"
    End Sub

    Private Sub Form5_FormClosing(sender As Object, e As FormClosingEventArgs) Handles MyBase.FormClosing
        Form1.Close()
    End Sub
End Class

注意我在Vista上测试了这个

1 个答案:

答案 0 :(得分:0)

我已经解决了问题,问题是每个操作系统的appdata文件夹都不同:D

我用它来修复它

Dim appData As String = GetFolderPath(SpecialFolder.ApplicationData)


client.DownloadFileAsync(New Uri("FILE_URL"), appData & "\Software_update.exe")