Web development India freelance website designer developer India SEO

{\rtf1\ansi\ansicpg1252\deff0\deflang1044{\fonttbl{\f0\fnil\fcharset0 MS Sans Serif;}}
\viewkind4\uc1\pard\f0\fs17 Download a file from the internet (without a prompt dialog)
\par
\par The following routine downloads a file from the internet without prompting the user first.
\par
\par Option Explicit
\par 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
\par Private Declare Function InternetOpen Lib "wininet" Alias "InternetOpenA" (ByVal sAgent As String, ByVal lAccessType As Long, ByVal sProxyName As String, ByVal sProxyBypass As String, ByVal lFlags As Long) As Long
\par Private Declare Function InternetCloseHandle Lib "wininet" (ByVal hInet As Long) As Integer
\par
\par
\par 'Purpose : Retreview text from a web site
\par 'Inputs : sURLFileName The URL and file name to download.
\par ' sSaveToFile The filename to save the file to.
\par ' [bOverwriteExisting] If True overwrites the file if it existings
\par 'Outputs : Returns True on success.
\par
\par Function InternetGetFile(sURLFileName As String, sSaveToFile As String, Optional bOverwriteExisting As Boolean = False) As Boolean
\par Dim lRet As Long
\par Const S_OK As Long = 0, E_OUTOFMEMORY = &H8007000E
\par Const INTERNET_OPEN_TYPE_PRECONFIG = 0, INTERNET_FLAG_EXISTING_CONNECT = &H20000000
\par Const INTERNET_OPEN_TYPE_DIRECT = 1, INTERNET_OPEN_TYPE_PROXY = 3
\par Const INTERNET_FLAG_RELOAD = &H80000000
\par
\par 'on error resume next
\par 'Create an internet connection
\par lRet = InternetOpen("", INTERNET_OPEN_TYPE_DIRECT, vbNullString, vbNullString, 0)
\par
\par If bOverwriteExisting Then
\par If Len(Dir$(sSaveToFile)) Then
\par VBA.Kill sSaveToFile
\par End If
\par End If
\par 'Check file doesn't already exist
\par If Len(Dir$(sSaveToFile)) = 0 Then
\par 'Download file
\par lRet = URLDownloadToFile(0&, sURLFileName, sSaveToFile, 0&, 0)
\par If Len(Dir$(sSaveToFile)) Then
\par 'File successfully downloaded
\par InternetGetFile = True
\par Else
\par 'Failed to download file
\par If lRet = E_OUTOFMEMORY Then
\par Debug.Print "The buffer length is invalid or there was insufficient memory to complete the operation."
\par Else
\par Debug.Print "Error occurred " & lRet & " (this is probably a proxy server error)."
\par End If
\par InternetGetFile = False
\par End If
\par End If
\par On Error GoTo 0
\par
\par End Function
\par
\par 'Demonstration routine, downloads an image from vbusers.com
\par 'to the c: drive
\par Sub Test()
\par If InternetGetFile("http://www.vbusers.com/images/default/top/top_navi_01.gif", "c:\\top_navi_01.gif", True) Then
\par MsgBox "Successfully downloaded file!"
\par Else
\par MsgBox "Failed to download file!"
\par End If
\par End Sub
\par }
Download a file from the internet 2

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150

India web developer web development India | India web development company India ecommerce web developer