加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

下载文件 – VB6

发布时间:2020-12-17 00:27:48 所属栏目:大数据 来源:网络整理
导读:有谁知道如何下载文件(不打开网页),并将其保存到Visual Basic 6.0中的目录? 如果您只想使用代码(没有Internet传输控制),VBNet.mvps.org有一篇非常好的使用URLDownloadToFile API调用的how-to文章. 来自文章: The URLDownloadToFile API is available on al
有谁知道如何下载文件(不打开网页),并将其保存到Visual Basic 6.0中的目录?
如果您只想使用代码(没有Internet传输控制),VBNet.mvps.org有一篇非常好的使用URLDownloadToFile API调用的how-to文章.

来自文章:

The URLDownloadToFile API is available
on all versions of the Windows
operating system (except Win3,
WinNT3.x). By passing the remote file
name and the local file path and name,
the API downloads the bits of the
specified file saving them as the
target name. The function works with
all file types – plain text,images,
html,mpg,wav and zip files etc.
without modification to the routine or
concern for the file being downloaded,
nor is there any apparent size
restriction or limitation.

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 Const ERROR_SUCCESS As Long = 0
Private Const BINDF_GETNEWESTVERSION As Long = &H10
Private Const INTERNET_FLAG_RELOAD As Long = &H80000000

Public Function DownloadFile(sSourceUrl As String,_
                             sLocalFile As String) As Boolean

  //'Download the file. BINDF_GETNEWESTVERSION forces 
  //'the API to download from the specified source. 
  //'Passing 0& as dwReserved causes the locally-cached 
  //'copy to be downloaded,if available. If the API 
  //'returns ERROR_SUCCESS (0),DownloadFile returns True.
   DownloadFile = URLDownloadToFile(0&,_
                                    sSourceUrl,_
                                    sLocalFile,_
                                    BINDF_GETNEWESTVERSION,_
                                    0&) = ERROR_SUCCESS

End Function

仅供参考 – 在Windows 7上进行测试时,它只会返回缓存版本,因此我必须先使用文章中提到的额外功能来清除它(并且可以正常工作).

Private Declare Function DeleteUrlCacheEntry Lib "Wininet.dll" _
   Alias "DeleteUrlCacheEntryA" _
  (ByVal lpszUrlName As String) As Long

然后,首先使用目标URL调用上述函数,以清除缓存.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读