Question

Je ne parviens à télécharger aucun fichier avec le code suivant :

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

Les erreurs suivantes apparaîtront :(traduit de l'allemand vers l'anglais) :

À partir de la fenêtre contextuelle d'erreur Microsoft :enter image description here

==> Une exception non traitée du type "System.Net.WebException" est apparue dans System.dll.

Et au niveau du débogueur :enter image description here

==> Exceptions :Déclenché:"Un argument non valide a été spécifié" (System.Net.Sockets.SocketException) System.Net.Sockets.SocketException a été déclenchée."Un argument non valide a été spécifié"

CODE COMPLET :

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
Était-ce utile?

La solution

Est-ce que le dossier C:\TEST exister?Aussi, à partir de la documentation :

Lorsque vous utilisez cette méthode dans une application de niveau intermédiaire, telle qu'une page ASP.NET, vous recevrez une erreur si le compte sous lequel l'application s'exécute n'est pas autorisé à accéder au fichier.

Si vous souhaitez cette méthode dans une application de Middle-Tear, par exemple.B.Un site ASP.NET vous permet d'obtenir un mélange d'options lors du contact, sans que la réponse ne soit prise en charge par un utilisateur de la date de publication.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top