|
-
Mar 23rd, 2002, 10:00 PM
#1
Thread Starter
Member
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.
-
Mar 23rd, 2002, 10:05 PM
#2
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
-
Mar 23rd, 2002, 10:11 PM
#3
Thread Starter
Member
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?
-
Mar 23rd, 2002, 11:36 PM
#4
Thread Starter
Member
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
-
Mar 24th, 2002, 12:43 AM
#5
VB Code:
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
Public Function DownloadFile(URL As String, LocalFilename As String) As Boolean
Dim lngRetVal As Long
lngRetVal = URLDownloadToFile(0, URL, LocalFilename, 0, 0)
If lngRetVal = 0 Then DownloadFile = True
End Function
Private Sub Form_Load()
DownloadFile "http://www.allapi.net", "c:\allapi.htm"
End Sub
-
Mar 24th, 2002, 12:45 AM
#6
In your case I guess you would use it like this:
VB Code:
DownloadFile "Http://www.microsoft.com/library/images/gifs/toolbar/home.gif", "C:\vbbb\http\home.gif"
-
Mar 24th, 2002, 11:56 AM
#7
Thread Starter
Member
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??????
-
Mar 24th, 2002, 12:18 PM
#8
Hyperactive Member
I've just tried the following code and it downloaded the gif without problem:
VB Code:
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
Public Function DownloadFile(URL As String, LocalFilename As String) As Boolean
Dim lngRetVal As Long
lngRetVal = URLDownloadToFile(0, URL, LocalFilename, 0, 0)
If lngRetVal = 0 Then DownloadFile = True
End Function
Private Sub Form_Load()
DownloadFile "Http://www.microsoft.com/library/images/gifs/toolbar/home.gif", "c:\temp\home.gif"
End Sub
When I used IE to look at the file, it is only 211 bytes - not 5 or 56kb.
-
Mar 24th, 2002, 12:19 PM
#9
The picture isn't missing
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|