|
-
Aug 8th, 2006, 09:04 PM
#1
download file from net - w/o events
am looking for a really simple (and compatable) way of downloading a file from the net - i also want my app not to run the next line of code until this has happened
i have seen api to do this before but cant seem to find any atm
thanks in advance
Kris Bennett
-
Aug 8th, 2006, 09:30 PM
#2
Re: download file from net - w/o events
Try this. You need a form with an Internet Transfer Control called inetDownload on it.
VB Code:
Option Explicit
Private Sub Form_Load()
DownLoadFromURL "http://www.yourwebsite.com/files/", "filetodownload.txt"
Unload Me
End Sub
Private Sub DownLoadFromURL(ByVal url As String, ByVal filename As String)
'
' Download a file from a given URL
'
Dim bytes() As Byte
Dim fnum As Integer
Dim ftext As String
'
' Download the file and load into byte array
'
ftext = url & filename
bytes() = inetDownload.OpenURL(ftext, icByteArray)
fnum = FreeFile
'
' Write the downloaded file to disk
'
Open App.Path & "\" & filename For Binary Access Write As #fnum
Put #fnum, , bytes()
Close #fnum
End Sub
Pete
No trees were harmed in the making of this post, however a large number of electrons were greatly inconvenienced.
-
Aug 8th, 2006, 10:47 PM
#3
Re: download file from net - w/o events
um does any one no how to do it without using 3rd party controls?
thanks
Kris
-
Aug 8th, 2006, 10:53 PM
#4
Re: download file from net - w/o events
It took about 5 seconds of searching to turn up this link....
http://www.devx.com/vb2themax/Tip/19203
Remember... Google is your friend
Pete
No trees were harmed in the making of this post, however a large number of electrons were greatly inconvenienced.
-
Aug 8th, 2006, 11:07 PM
#5
Re: download file from net - w/o events
Or you can use the URLDownloadToFile API function.
VB Code:
Private Declare Function URLDownloadToFile Lib "URLMON.dll" Alias "URLDownloadToFileA" ( _
ByVal pCaller As Long, _
ByVal szUrl As String, _
ByVal szFileName As String, _
ByVal dwFlags As Long, _
ByVal lpfnCB As Long _
) As Long
Public Sub DownloadFile(ByVal sUrl As String, ByVal sLocalFile As String)
Call URLDownloadToFile(0&, sUrl, sLocalFile, 0&, 0&)
End Sub
Simply use it like this:
VB Code:
Call DownloadFile("http://www.domain.com/theFile.zip", "c:\SomePath\theFile.zip")
-
Aug 8th, 2006, 11:12 PM
#6
Re: download file from net - w/o events
 Originally Posted by Joacim Andersson
Or you can use the URLDownloadToFile API function
You just need to be aware that this requires that Internet Explorer 5 or greater is installed.
Pete
No trees were harmed in the making of this post, however a large number of electrons were greatly inconvenienced.
-
Aug 8th, 2006, 11:14 PM
#7
Re: download file from net - w/o events
 Originally Posted by pnish
You just need to be aware that this requires that Internet Explorer 5 or greater is installed.
Is there anyone who still use IE4 or earlier
-
Aug 8th, 2006, 11:22 PM
#8
Re: download file from net - w/o events
The sad truth is that you never really know until your app breaks...
Pete
No trees were harmed in the making of this post, however a large number of electrons were greatly inconvenienced.
-
Aug 8th, 2006, 11:27 PM
#9
PowerPoster
Re: download file from net - w/o events
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
Private 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 Command1_Click()
If DownloadFile("http://www.mywebsite.com/somefile.exe", "c:\somefile.exe") Then
Debug.Print "Download Complete"
End If
End Sub
-
Aug 8th, 2006, 11:33 PM
#10
Re: download file from net - w/o events
 Originally Posted by pnish
The sad truth is that you never really know until your app breaks... 
Well, putting IE5 or later as a requirement for your application should not be a problem. Besides you can always use code like the following to test if it's installed or not before calling URLDownloadToFile
VB Code:
Private Declare Function DllGetVersion Lib "shlwapi" ( _
dwVersion As DllVersionInfo _
) As Long
Private Type DllVersionInfo
cbSize As Long
dwMajorVersion As Long
dwMinorVersion As Long
dwBuildNumber As Long
dwPlatformID As Long
End Type
Public Function UsesIE5(ByRef sVersionString As String) As Boolean
Dim dvi As DllVersionInfo
dvi.cbSize = Len(dvi)
Call DllGetVersion(dvi)
sVersionString = dvi.dwMajorVersion & "." & dvi.dwMinorVersion & "." & _
dvi.dwBuildNumber
UsesIE5 = (dvi.dwMajorVersion >= 5)
End Function
Now simply use this:
VB Code:
Dim sIEVer As String
If UsesIE5(sIEVer) = False Then
MsgBox "You are currently running version " & sIEVer & " of Internet Explorer" & vbCrLf & _
"This application requires version 5.0 or later.", vbInformation
End If
Last edited by Joacim Andersson; Aug 8th, 2006 at 11:36 PM.
-
Aug 8th, 2006, 11:36 PM
#11
Re: download file from net - w/o events
 Originally Posted by Joacim Andersson
Well, putting IE5 or later as a requirement for your application should not be a problem. Besides you can always use code like the following to test if it's installed or not before calling URLDownloadToFile
I agree. The whole point of my post was to make i00 aware of the restriction.
Pete
No trees were harmed in the making of this post, however a large number of electrons were greatly inconvenienced.
-
Aug 8th, 2006, 11:43 PM
#12
Re: download file from net - w/o events
@Rory. What's the difference between your post and the code I posted earlier?
-
Aug 9th, 2006, 12:00 AM
#13
PowerPoster
Re: download file from net - w/o events
Its a function so it tells the user when it is downloaded . ..
-
Aug 9th, 2006, 12:09 AM
#14
Re: download file from net - w/o events
 Originally Posted by rory
Its a function so it tells the user when it is downloaded . ..
No it doesn't. It tells the user if it was able to download it perhaps. Neither the function nor the sub returns until the file is downloaded (or the download failed for some reason).
-
Aug 9th, 2006, 12:15 AM
#15
PowerPoster
Re: download file from net - w/o events
 Originally Posted by Joacim Andersson
No it doesn't. It tells the user if it was able to download it perhaps. Neither the function nor the sub returns until the file is downloaded (or the download failed for some reason).
thats what i said .. it tells them when it is downloaded. (not when it is downloading)
Edit. .. whoops excuse my Bahamian, that should be "once it has completed the download" .. (1am to my defence)
Last edited by rory; Aug 9th, 2006 at 12:21 AM.
-
Aug 9th, 2006, 04:46 AM
#16
PowerPoster
Re: download file from net - w/o events
this one gives you a progress as it is downloaded .. check it out ..
just threw it together tonight 
ps. not for large file downloads. ..
Last edited by rory; Aug 9th, 2006 at 04:52 AM.
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
|