我目前正在使用Net.WebClient从互联网上下载文件。现在,我想做另一件事。 只有在我开始使用此子中的参数e.TotalBytesToReceive下载后才能知道flie大小
Private Sub W_DownloadProgressChanged(ByVal sender As Object, ByVal e As _
Net.DownloadProgressChangedEventArgs) Handles W.DownloadProgressChanged
如何在不下载的情况下获取链接的文件大小参数?
答案 0 :(得分:2)
使用WebClient ResponseHeaders
:
Public Shared Function GetFileSize(url As String) As Long
Using obj As New WebClient()
Using s As Stream = obj.OpenRead(url)
Return Long.Parse(obj.ResponseHeaders("Content-Length").ToString())
End Using
End Using
End Function