0

我无法使用以下代码下载任何文件:

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
    DownloadFile("http://mirror.switch.ch/ftp/mirror/videolan/vlc/2.0.3/vlc-2.0.3.tar.xz", "C:\TEST\vlc-2.0.3.tar.xz")
End Sub

Public Sub DownloadFile(ByVal _URL As String, ByVal _SaveAs As String)
        Dim _WebClient As New System.Net.WebClient()
        _WebClient.DownloadFile(_URL, _SaveAs)
End Sub

将弹出以下错误:(从德语翻译成英语):

从 Microsoft 错误弹出窗口: 在此处输入图像描述

==> System.dll 中出现了来自“System.Net.WebException”类型的未处理异常。

在调试器中: 在此处输入图像描述

==> Exeption: Triggered: "An invalid argument has been specified" (System.Net.Sockets.SocketException) System.Net.Sockets.SocketException 已被触发。“指定了无效参数”

完整代码:

Imports System
Imports System.Net

Public Class Form2
    Dim str_hd As String

    Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load


        For Each drive As System.IO.DriveInfo In My.Computer.FileSystem.Drives
            Dim dbl_capacity As Double
            Dim dbl_free As Double
            Dim dbl_used As Double

            If drive.IsReady Then
                dbl_capacity = drive.TotalSize / 1073741824
                dbl_free = drive.TotalFreeSpace / 1073741824
                dbl_used = dbl_capacity - dbl_free

                dbl_capacity = Fix(dbl_capacity * 1) / 1
                dbl_free = Fix(dbl_free * 10) / 10
                dbl_used = Fix(dbl_used * 10) / 10


                str_hd = str_hd & "Laufwerk " & drive.Name & "  -  " _
                        & drive.VolumeLabel & vbCrLf _
                        & "Benutzt: " & dbl_used & " GB" & " / " & dbl_capacity & " GB" & vbCrLf & "Frei: " _
                        & dbl_free & "GB" & vbCrLf & "-------------------------------" & vbCrLf
            End If
        Next

        txtbox_hd.Text = str_hd

    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Form1.Close()
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        DownloadFile("http://www.aerztekammer-hamburg.de/berufsrecht/Berufsordnung.pdf", "C:\TEST\Berufsordnung.pdf")
    End Sub



    Public Sub DownloadFile(ByVal _URL As String, ByVal _SaveAs As String)
            Dim _WebClient As New System.Net.WebClient()
            _WebClient.DownloadFile(_URL, _SaveAs)
    End Sub

End Class
4

1 回答 1

1

文件夹C:\TEST存在吗?另外,从文档中:

在中间层应用程序(例如 ASP.NET 页面)中使用此方法时,如果执行应用程序的帐户没有访问文件的权限,您将收到错误消息。

Wenn Sie diese Methode in einer Anwendung der Middle-Tear verwenden, z。B. einer ASP.NET-Seite, erhalten Sie eine Fehlermeldung, wenn das Konto, unter dem die Anwendung ausgeführt wird, nicht über die Berechtigung zum Zugriff auf die Datei verfügt。

于 2012-10-01T12:53:13.170 回答