简体   繁体   English

在 vb.net 中获取下载文件的大小

[英]get the downloading file size in vb.net

I designed a download manager in vb.net, but I don't know how to get file size after downloading started, or when I put the url.我在vb.net中设计了一个下载管理器,但是我不知道如何在下载开始后或何时放置url时获取文件大小。

I searched on internet and here, and I found the httpwebrequest class, but I don't know how does it work and how can I add it in my project.我在互联网和这里搜索,我找到了httpwebrequest类,但我不知道它是如何工作的以及如何将它添加到我的项目中。

Use this function :使用此功能:

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

Here's an easy example of use :这是一个简单的使用示例:

MsgBox(Math.Round(GetDownloadSize("http://www.foo.com/file.mp3") / 1024 / 1024, 2) & " MB")

Source : https://stackoverflow.com/a/32340260/3970387来源: https : //stackoverflow.com/a/32340260/3970387

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM