本文介绍了获取文件大小,然后下载到vb的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!

我一直在视觉基础的web浏览器上工作。现在,我想做的是在下载文件之前获取文件大小,当我点击下载时,我想得到下载的mb的alrady数观看图片)

I have been working on a web browser in visual basic..Now,what I want to do is to the get file size before download it and when I click download I want to to get the number of the alrady downloaded Mbs(watch the picture)

感谢帮忙! p>

Thank's for help!

推荐答案

我做了一些研究,这可能是获取下载大小的最简单,最干净的方法字节):

I've done some research, and this would probably be the most simple and "cleanest" way of getting a download's size (in bytes):

Public Function GetDownloadSize(ByVal URL As String) As Long
    Dim r As Net.WebRequest = Net.WebRequest.Create(URL)
    r.Method = Net.WebRequestMethods.Http.Head
    Using rsp = r.GetResponse()
        Return rsp.ContentLength
    End Using
End Function

信用到。

上面的代码将会读取文件,而不是阅读它的身体。这意味着文件需要下载,只是为了检查它的大小。

The above code will read the response headers of the file, rather than reading the body of it. This means that the file does not require to get downloaded, just to check it's size.

这就是为什么一些代码需要文件首先实际下载;他们正在阅读文件的正文,而不是标题。

This is the reason to why some codes requires the file to actually get downloaded at first; they're reading the file's body rather than it's headers.

希望这有帮助!

这篇关于获取文件大小,然后下载到vb的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-08 13:18
查看更多