Download a file with one API call

If you have Internet Explorer 5 or later version, you can use an API call to download a file from the Internet withouth displaying any message box. The following code downloads the demo copy of our VBMaximizer VB6 add-in from our site to the C: directory on your hard disk:

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' Note that this file is 2M, so you might want to try with something simplerDim errcode As LongDim url As StringDim localFileName As Stringurl = ""localFileName = ""errcode = URLDownloadToFile(0, url, localFileName, 0, 0)If errcode = 0 Then    MsgBox "Download ok"Else    MsgBox "Error while downloading"End If

Share the Post:
Share on facebook
Share on twitter
Share on linkedin


Recent Articles: