Results 1 to 9 of 9

Thread: Downloading a file

  1. #1

    Thread Starter
    Member
    Join Date
    Mar 2002
    Posts
    43

    Downloading a file

    I'm trying to download a file from the internet using code. It's a graphic file. I have learned that Inet is the best way to do this, but it's still not working for me. Does anyone have any code to do this? Thanks.

  2. #2
    jim mcnamara
    Guest
    IE downloads all files this way:
    Code:
    Private Declare Function DoFileDownload Lib "shdocvw.dll" (ByVal lpszFile As String) As Long
    Private Sub Form_Load()
        'KPD-Team 2000
        'URL: http://www.allapi.net/
        'E-Mail: [email protected]
       DoFileDownload StrConv("http://www.microsoft.com/", vbUnicode)
    End Sub

  3. #3

    Thread Starter
    Member
    Join Date
    Mar 2002
    Posts
    43
    OK, that's great. I'm trying to get it to download specific files off a website and save them to the harddrive on my local machine?

  4. #4

    Thread Starter
    Member
    Join Date
    Mar 2002
    Posts
    43
    This is the code I already have, but it doesn't seem to work for image files. It will download the file, but it's empty. Do you know why that would be?

    Private Sub Command1_Click()
    Text1.Text = Inet1.openURL("http://www.microsoft.com/vbasic/default.htm")
    End Sub

    Private Sub Command2_click()
    Dim bytdata() As Integer

    bytdata() = Inet1.openURL("Http://www.microsoft.com/library/images/gifs/toolbar/home.gif", icByteArray)
    bytdata() = Inet1.openURL
    Open "C:\vbbb\http\home.gif" For Binary Access Write As #1
    Put #1, , bytdata()
    Close #1

    MsgBox "home.gif downloaded"
    End Sub

  5. #5
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    VB Code:
    1. Private Declare Function URLDownloadToFile Lib "urlmon" Alias "URLDownloadToFileA" (ByVal pCaller As Long, ByVal szURL As String, ByVal szFileName As String, ByVal dwReserved As Long, ByVal lpfnCB As Long) As Long
    2. Public Function DownloadFile(URL As String, LocalFilename As String) As Boolean
    3.     Dim lngRetVal As Long
    4.     lngRetVal = URLDownloadToFile(0, URL, LocalFilename, 0, 0)
    5.     If lngRetVal = 0 Then DownloadFile = True
    6. End Function
    7. Private Sub Form_Load()
    8.     'example by Matthew Gates ([email protected])
    9.     DownloadFile "http://www.allapi.net", "c:\allapi.htm"
    10. End Sub

  6. #6
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    In your case I guess you would use it like this:

    VB Code:
    1. DownloadFile "Http://www.microsoft.com/library/images/gifs/toolbar/home.gif", "C:\vbbb\http\home.gif"

  7. #7

    Thread Starter
    Member
    Join Date
    Mar 2002
    Posts
    43

    Angry

    That still won't work. The size of the file is wrong. And when I go to bring it up it's 5kb instead of 56kb??????

  8. #8
    Hyperactive Member
    Join Date
    Jan 2000
    Location
    Edinburgh, Scotland
    Posts
    272
    I've just tried the following code and it downloaded the gif without problem:

    VB Code:
    1. Private Declare Function URLDownloadToFile Lib "urlmon" Alias "URLDownloadToFileA" (ByVal pCaller As Long, ByVal szURL As String, ByVal szFileName As String, ByVal dwReserved As Long, ByVal lpfnCB As Long) As Long
    2.  
    3.  
    4. Public Function DownloadFile(URL As String, LocalFilename As String) As Boolean
    5.     Dim lngRetVal As Long
    6.     lngRetVal = URLDownloadToFile(0, URL, LocalFilename, 0, 0)
    7.     If lngRetVal = 0 Then DownloadFile = True
    8. End Function
    9.  
    10.  
    11. Private Sub Form_Load()
    12.     DownloadFile "Http://www.microsoft.com/library/images/gifs/toolbar/home.gif", "c:\temp\home.gif"
    13. End Sub


    When I used IE to look at the file, it is only 211 bytes - not 5 or 56kb.

  9. #9
    The picture isn't missing BuggyProgrammer's Avatar
    Join Date
    Oct 2000
    Location
    Vancouver, Canada
    Posts
    5,217
    maybe it is still ownloading. if you have a 14 k modem it might take a while......
    Remember, if someone's post was not helpful, you can always rate their post negatively .

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