Results 1 to 7 of 7

Thread: [RESOLVED]Webclient downloader

  1. #1

    Thread Starter
    Member
    Join Date
    Dec 2018
    Posts
    61

    Resolved [RESOLVED]Webclient downloader

    Hi, whats wrong with this code? It doesnt work, because it doesnt download the file, only steps in the DownloadFileCompleted sub. Thank you!
    Code:
    Imports System.ComponentModel
    Imports System.Net
    
    Public Class Form2
        Dim hely As String
        Public WithEvents wc As System.Net.WebClient
        Private Sub Form2_Load(sender As Object, e As EventArgs) Handles MyBase.Load
            wc = New System.Net.WebClient
            FolderBrowserDialog1.ShowNewFolderButton = False
            FolderBrowserDialog1.Description = "Kérlek válaszd ki a mappát ahova telepiteni szeretnéd!"
            FolderBrowserDialog1.RootFolder = Environment.SpecialFolder.MyComputer
            If FolderBrowserDialog1.ShowDialog() = DialogResult.OK Then
                hely = FolderBrowserDialog1.SelectedPath
                Dim uri As Uri = New Uri("https://drive.google.com/uc?authuser=1&id=1N-ajoDD7VL4NyeRIsiETks2AqPpwbHbP&export=download")
                wc.DownloadFileAsync(uri, My.Computer.FileSystem.SpecialDirectories.Temp & "\klienstemp\client.rar")
            Else
                Me.Hide()
                Form1.Show()
            End If
        End Sub
        Private Sub wc_DownloadProgressChanged(sender As Object, e As DownloadProgressChangedEventArgs) Handles wc.DownloadProgressChanged
            ProgressBar1.Value = e.ProgressPercentage
            Label1.Text = "Méret: " & Int((e.BytesReceived / 1024) / 1024) & "/" & Int((e.TotalBytesToReceive / 1024) / 1024) & "Megabyte"
        End Sub
    
        Private Sub wc_DownloadFileCompleted(sender As Object, e As AsyncCompletedEventArgs) Handles wc.DownloadFileCompleted
            Label1.Text = ""
            MessageBox.Show("A letöltés befejeződött!", "Felhivás", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
        End Sub
    End Class
    Last edited by Daveeed; Jan 8th, 2019 at 09:09 AM.

  2. #2
    Frenzied Member cory_jackson's Avatar
    Join Date
    Dec 2011
    Location
    Fallbrook, California
    Posts
    1,145

    Re: Webclient downloader

    I'm not sure. Maybe it the wc.downloadfileasync method? What if you change that to wc.downloadfile?

  3. #3
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Webclient downloader

    You should be testing the e.Error property in the DownloadFileCompleted event handler to determine whether an exception was thrown and, if so, what it was.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  4. #4

    Thread Starter
    Member
    Join Date
    Dec 2018
    Posts
    61

    Re: Webclient downloader

    "An exception occured druing a Webclient request", maybe I'm using it to earlier, like the program hasnt started completely, or something?

  5. #5

    Thread Starter
    Member
    Join Date
    Dec 2018
    Posts
    61

    Re: Webclient downloader

    + I tried with simple DownloadFile, and it gives me the same: An unhandled exception of type 'System.Net.WebException' occurred in System.dll

    Additional information: An exception occurred during a WebClient request.

  6. #6
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Webclient downloader

    Look deeper into the exception. There's more information than that.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  7. #7

    Thread Starter
    Member
    Join Date
    Dec 2018
    Posts
    61

    Re: Webclient downloader

    Okay, finally I resolved it, thank you very much!

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width