Tipp 0355 Datei aus dem Internet downloaden
Autor/Einsender:
Datum:
  Julien Gedeon
28.08.2003
Entwicklungsumgebung:   VB 6
Wer sein Programm mit einer Download-Funktion ausstatten möchte, sollte sich diesen Tipp genauer anschauen. Mit der API-Funktion URLDownloadToFile braucht lediglich die gewünschte Download-Adresse (Parameter URL) und der Dateinamen (Parameter FileName) angegeben werden, unter dem die heruntergeladene Datei gespeichert werden soll. 
So lassen sich alle beliebigen Dateien wie auch HTML-Seiten herunterladen. Sie werden allerdings so gespeichert, wie der angegebene Server sie ausliefert.
 
Option Explicit

Private Declare Function URLDownloadToFile Lib "urlmon.dll" _
        Alias "URLDownloadToFileA" (ByVal pCaller As Long, _
        ByVal szURL As String, ByVal szFileName As String, _
        ByVal Reserved As Long, ByVal fnCB As Long) As Long

Private Sub Command1_Click()
  Dim retVal As Long

  If Left(txt_url.Text, 7) <> "http://" Then
    MsgBox "Die Url ist nicht oder nur unvollständig angegeben.", _
          vbOKOnly + vbInformation, "Fehler"
    Exit Sub

  ElseIf Len(txt_localfile.Text) < 4 Then
    MsgBox "Die Speicher-Adresse ist nicht oder nur " & _
           "unvollständig angegeben.", _
           vbOKOnly + vbInformation, "Fehler"
    Exit Sub
  End If

  Me.MousePointer = vbHourglass
  Command1.Enabled = False

  retVal = URLDownloadToFile( _
        0, txt_url.Text, txt_localfile.Text, 0, 0)

  Me.MousePointer = 99
  Command1.Enabled = True

  If retVal = 0 Then
    MsgBox txt_url.Text & _
           " wurde erfolgreich heruntergeladen und als" & _
           vbCrLf & txt_localfile & " gespeichert!", _
           vbOKOnly + vbInformation, "Download"
  Else
    MsgBox "Beim Download von " & txt_url.Text & _
           " ist ein Fehler aufgetreten !", _
           vbOKOnly + vbInformation, "Fehler beim Download"
  End If

End Sub
 
Weitere Links zum Thema
Datei-Download mit Dialog und Progressbar
FTP mit der wininet.dll
Webseite laden und speichern

Windows-Version
95
98/SE
ME
NT
2000
XP
Vista
Win 7
VB-Version
VBA 5
VBA 6
VB 4/16
VB 4/32
VB 5
VB 6


Download  (2,8 kB) Downloads bisher: [ 4211 ]

Vorheriger Tipp Zum Seitenanfang Nächster Tipp

Startseite | Projekte | Tutorials | API-Referenz | VB-/VBA-Tipps | Komponenten | Bücherecke | VB/VBA-Forum | VB.Net-Forum | DirectX-Forum | Foren-Archiv | DirectX | VB.Net-Tipps | Chat | Spielplatz | Links | Suchen | Stichwortverzeichnis | Feedback | Impressum

Seite empfehlen Bug-Report
Letzte Aktualisierung: Montag, 24. Oktober 2011