-1

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.

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.

Drarig29
  • 1,902
  • 1
  • 19
  • 42
Pro-Fun
  • 21
  • 1
  • 7

1 Answers1

0

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

Community
  • 1
  • 1
Drarig29
  • 1,902
  • 1
  • 19
  • 42