Dateien herunterladen und Checksumme erstellen.

  • VB.NET

Es gibt 22 Antworten in diesem Thema. Der letzte Beitrag () ist von coolerj.

    EiPott schrieb:

    String.Split(vbCrLf)

    Leider hat kann .NET nicht nach String-Delimitern trenne, sondern nur nach Char :huh:

    Man kann sich z.B. so behelfen

    VB.NET-Quellcode

    1. Dim line As String = "1" & vbCrLf & "2" & vbCrLf & "3"
    2. Dim sa() As String = line.Split(New Char() {vbCr, vbLf}, StringSplitOptions.RemoveEmptyEntries)

    oder man nimmt gleich die alte VB6 Methode aus dem Microsoft.VisualBasic Namespace:

    VB.NET-Quellcode

    1. Dim line As String = "1" & vbCrLf & "2" & vbCrLf & "3"
    2. Dim sa() As String = Microsoft.VisualBasic.Split(line, vbCrLf)
    Ok jetzt hab ich ein Problem wenn die Datei nicht existier schmiert das ganze ab.

    VB.NET-Quellcode

    1. Imports System.Security.Cryptography
    2. Imports System.Text
    3. Imports System.IO
    4. Imports System.Net
    5. Public Class Form1
    6. Private Sub PictureBox1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureBox1.Click
    7. End Sub
    8. Public Function MD5FileHash(ByVal sFile As String) As String
    9. Dim MD5 As New MD5CryptoServiceProvider
    10. Dim Hash As Byte()
    11. Dim Result As String = ""
    12. Dim Tmp As String = ""
    13. Dim FN As New FileStream(sFile, FileMode.Open, FileAccess.Read, FileShare.Read, 8192)
    14. MD5.ComputeHash(FN)
    15. FN.Close()
    16. Hash = MD5.Hash
    17. For i As Integer = 0 To Hash.Length - 1
    18. Tmp = Hex(Hash(i))
    19. If Len(Tmp) = 1 Then Tmp = "0" & Tmp
    20. Result += Tmp
    21. Next
    22. Return Result
    23. End Function
    24. Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    25. TextBox1.Text = "Patchlist wird geladen..."
    26. Button1.Enabled = False
    27. Dim webClient As New WebClient
    28. Dim seitenInhalt As String = webClient.DownloadString("http://localhost/patcher/index.php")
    29. TextBox1.Text = "Patchlist wurde geladen" & vbCrLf & TextBox1.Text
    30. Dim dateien As Array = seitenInhalt.Split(vbCrLf)
    31. For Each datei As String In dateien
    32. Dim splitarray As Array = datei.Split("|")
    33. If splitarray(0) = " " Then
    34. Else
    35. TextBox1.Text = splitarray(0) & " wird geprüft..." & vbCrLf & TextBox1.Text
    36. Dim localHash = MD5FileHash(Application.StartupPath() & splitarray(0))
    37. If localHash = splitarray(1) Then
    38. TextBox1.Text = " ist aktuell." & TextBox1.Text
    39. Else
    40. TextBox1.Text = " wird geladen." & TextBox1.Text
    41. webClient.DownloadFile("http://localhost/patcher/client/" & splitarray(0), Application.StartupPath() & splitarray(0))
    42. End If
    43. End If
    44. Next
    45. End Sub
    46. End Class

    Ich will haben das er diese datei dann ganz einfach runterlädt

    VB.NET-Quellcode

    1. Imports System.Net
    2. Public Class Form1
    3. Private Sub PictureBox1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureBox1.Click
    4. End Sub
    5. Public Function MD5FileHash(ByVal sFile As String) As String
    6. Dim MD5 As New MD5CryptoServiceProvider
    7. Dim Hash As Byte()
    8. Dim Result As String = ""
    9. Dim Tmp As String = ""
    10. If File.Exists(sFile) Then
    11. Dim FN As New FileStream(sFile, FileMode.Open, FileAccess.Read, FileShare.Read, 8192)
    12. MD5.ComputeHash(FN)
    13. FN.Close()
    14. Hash = MD5.Hash
    15. For i As Integer = 0 To Hash.Length - 1
    16. Tmp = Hex(Hash(i))
    17. If Len(Tmp) = 1 Then Tmp = "0" & Tmp
    18. Result += Tmp
    19. Next
    20. Return Result
    21. Else
    22. Return 0
    23. End If
    24. End Function
    25. Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    26. TextBox1.Text = "Patchlist wird geladen..."
    27. Button1.Enabled = False
    28. Dim webClient As New WebClient
    29. Dim seitenInhalt As String = webClient.DownloadString("http://localhost/patcher/index.php")
    30. TextBox1.Text = "Patchlist wurde geladen" & vbCrLf & TextBox1.Text
    31. Dim dateien As Array = seitenInhalt.Split(vbCrLf)
    32. For Each datei As String In dateien
    33. Dim splitarray As Array = datei.Split("|")
    34. If splitarray(0) = " " Then
    35. Else
    36. TextBox1.Text = splitarray(0) & " wird geprüft..." & vbCrLf & TextBox1.Text
    37. Dim localHash = MD5FileHash(Application.StartupPath() & "/" & splitarray(0))
    38. If localHash = splitarray(1) Then
    39. TextBox1.Text = " ist aktuell." & TextBox1.Text
    40. Else
    41. TextBox1.Text = " wird geladen." & TextBox1.Text
    42. webClient.DownloadFile("http://localhost/patcher/client/" & splitarray(0), Application.StartupPath() & "/" & splitarray(0))
    43. End If
    44. End If
    45. Next
    46. End Sub
    47. End Class


    Jetzt kommt Ausnahmefehler während einer WebClient-Anforderung

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