Downloadprogressbar fonktoniert nicht

  • VB.NET

Es gibt 27 Antworten in diesem Thema. Der letzte Beitrag () ist von Sami41194.

    Downloadprogressbar fonktoniert nicht

    Hallo Forum
    beim download geht die progressbar nicht mit sie lädt sich erst wenn die datei schon am pc ist

    VB.NET-Quellcode

    1. Option Strict On
    2. Imports System.Net
    3. Public Class Database_Load
    4. WithEvents WebCilient As New Net.WebClient
    5. Private Sub Database_Load_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    6. Try
    7. WebCilient = New WebClient
    8. WebCilient.Credentials = New Net.NetworkCredential(" ", " ")
    9. Dim Uri As New Uri("ftp://sami41194.sa.funpic.de/Test.mp3")
    10. WebCilient.DownloadFileAsync(Uri, My.Application.Info.DirectoryPath & "\Test.mp3")
    11. Catch ex As Exception
    12. MsgBox(ex.ToString)
    13. End Try
    14. End Sub
    15. Private Sub WebCilient_DownloadProgressChanged(ByVal sender As Object, ByVal e As System.Net.DownloadProgressChangedEventArgs) Handles WebCilient.DownloadProgressChanged
    16. ProgressBar1.Value = e.ProgressPercentage
    17. End Sub
    18. End Class


    Danke

    PS: Vl. hat noch jemand nen code der mir die kb´s angibt der datei angibt und die schon gedownloaded wurden

    Dieser Beitrag wurde bereits 1 mal editiert, zuletzt von „Sami41194“ ()

    Meinst du sowas hier:

    VB.NET-Quellcode

    1. Private Sub WebCilient_DownloadProgressChanged(ByVal sender As Object, ByVal e As System.Net.DownloadProgressChangedEventArgs) Handles WebCilient.DownloadProgressChanged
    2. Dim Empfangene_Bytes As Integer = e.BytesReceived
    3. Dim Gesamt_Bytes As Integer = e.TotalBytesToReceive
    4. Dim Fortschritt As Integer = e.ProgressPercentage
    5. ProgressBar1.Value = Fortschritt
    6. End Sub
    Der Code geht bei mir nicht
    bei der gesamten datei größe wird -1 angegen und die prgressbar lädt sich erst nach dem downlaod der datei

    VB.NET-Quellcode

    1. Public Class Database_Load
    2. WithEvents WebCilient As New Net.WebClient
    3. Private Sub Database_Load_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    4. Try
    5. WebCilient.Credentials = New Net.NetworkCredential("")
    6. Dim Uri As New Uri("ftp:///Test.mp3")
    7. WebCilient.DownloadFileAsync(Uri, My.Application.Info.DirectoryPath & "\Test.mp3")
    8. Catch ex As Exception
    9. MsgBox(ex.ToString)
    10. End Try
    11. End Sub
    12. Private Sub WebCilient_DownloadProgressChanged(ByVal sender As Object, ByVal e As System.Net.DownloadProgressChangedEventArgs) Handles WebCilient.DownloadProgressChanged
    13. Dim Empfangene_Bytes As Integer = CInt(e.BytesReceived)
    14. Dim Gesamt_Bytes As Integer = CInt(e.TotalBytesToReceive)
    15. Dim Fortschritt As Integer = e.ProgressPercentage
    16. ProgressBar1.Value = Fortschritt
    17. Label2.Text = Empfangene_Bytes
    18. Label3.Text = Gesamt_Bytes
    19. End Sub
    20. End Class

    Sami41194 schrieb:

    Dim Uri As New Uri("ftp:///Test.mp3")


    Du hast 3x /// in der URL!!!


    Hier ein kleines Beispiel was 100% funktioniert.

    VB.NET-Quellcode

    1. Public Class Form1
    2. WithEvents WebCilient As New Net.WebClient
    3. Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    4. Dim Uri As New Uri("http://download.thinkbroadband.com/5MB.zip")
    5. WebCilient.DownloadFileAsync(Uri, IO.Path.Combine(My.Application.Info.DirectoryPath, "5MB.zip"))
    6. End Sub
    7. Private Sub WebCilient_DownloadProgressChanged(ByVal sender As Object, ByVal e As System.Net.DownloadProgressChangedEventArgs) Handles WebCilient.DownloadProgressChanged
    8. Dim Empfangene_Bytes As Integer = CInt(e.BytesReceived)
    9. Dim Gesamt_Bytes As Integer = CInt(e.TotalBytesToReceive)
    10. ProgressBar1.Value = e.ProgressPercentage
    11. Label2.Text = CStr(Math.Round(Empfangene_Bytes / 1024, 0) & " Kb")
    12. Label3.Text = CStr(Math.Round(Gesamt_Bytes / 1024, 0) & " Kb")
    13. End Sub
    14. Private Sub WebCilient_DownloadFileCompleted(ByVal sender As Object, ByVal e As System.ComponentModel.AsyncCompletedEventArgs) Handles WebCilient.DownloadFileCompleted
    15. MsgBox("fertig")
    16. End Sub
    17. End Class
    GOOGLE ist mein Meister :)

    Dieser Beitrag wurde bereits 1 mal editiert, zuletzt von „Bady“ ()

    ok zurück zum eig thema
    ich schaff es die datei zu downloaden aber wiso spielen die labes und progressbar verückt

    PS die progressbar wo angezeit wird wie viel schon geladen wurde scheint zu fonktioniern nur noch die frage wiso die andern nicht

    VB.NET-Quellcode

    1. Public Class Database_Load
    2. WithEvents WebCilient As New Net.WebClient
    3. Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    4. WebCilient.Credentials = New Net.NetworkCredential("USER", "PW")
    5. Dim Uri As New Uri("ftp:/server.de/Test.mp3")
    6. WebCilient.DownloadFileAsync(Uri, IO.Path.Combine(My.Application.Info.DirectoryPath, "Test.mp3"))
    7. End Sub
    8. Private Sub WebCilient_DownloadProgressChanged(ByVal sender As Object, ByVal e As System.Net.DownloadProgressChangedEventArgs) Handles WebCilient.DownloadProgressChanged
    9. Dim Empfangene_Bytes As Integer = CInt(e.BytesReceived)
    10. Dim Gesamt_Bytes As Integer = CInt(e.TotalBytesToReceive)
    11. ProgressBar1.Value = e.ProgressPercentage
    12. Label2.Text = CStr(Math.Round(Empfangene_Bytes / 1024, 0) & " Kb")
    13. Label3.Text = CStr(Math.Round(Gesamt_Bytes / 1024, 0) & " Kb")
    14. End Sub
    15. Private Sub WebCilient_DownloadFileCompleted(ByVal sender As Object, ByVal e As System.ComponentModel.AsyncCompletedEventArgs) Handles WebCilient.DownloadFileCompleted
    16. MsgBox("fertig")
    17. End Sub
    18. End Class

    Slayers schrieb:

    Nur weil er nen ftp hat muss er keinen http Server laufen haben ;)

    Ist aber nen FreeWebspace, und damit läuft http... also bitte erst Informieren..



    Was spielt verrückt? Eine bessere Beschreibung würde helfen
    Habs grad mit deiner url getestet... geht einwandfrei:

    VB.NET-Quellcode

    1. Public Class Form1
    2. WithEvents WebCilient As New Net.WebClient
    3. Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    4. Dim Uri As New Uri("http://sami41194.sa.funpic.de/Test.mp3")
    5. WebCilient.DownloadFileAsync(Uri, IO.Path.Combine(My.Application.Info.DirectoryPath, "Test.mp3"))
    6. End Sub
    7. Private Sub WebCilient_DownloadProgressChanged(ByVal sender As Object, ByVal e As System.Net.DownloadProgressChangedEventArgs) Handles WebCilient.DownloadProgressChanged
    8. Dim Empfangene_Bytes As Integer = CInt(e.BytesReceived)
    9. Dim Gesamt_Bytes As Integer = CInt(e.TotalBytesToReceive)
    10. Dim Fortschritt As Integer = e.ProgressPercentage
    11. ProgressBar1.Value = Fortschritt
    12. Label2.Text = CStr(Math.Round(Empfangene_Bytes / 1024, 0) & " Kb")
    13. Label3.Text = CStr(Math.Round(Gesamt_Bytes / 1024, 0) & " Kb")
    14. End Sub
    15. Private Sub WebCilient_DownloadFileCompleted(ByVal sender As Object, ByVal e As System.ComponentModel.AsyncCompletedEventArgs) Handles WebCilient.DownloadFileCompleted
    16. MsgBox("fertig")
    17. End Sub
    GOOGLE ist mein Meister :)