Hey there DaniWeb!

I have a bit of a problem! I am in need of a way to get the size of a remote file, without download the file itself (so that i can show download status in a status bar)

is this even possible?

Thank you a lot, Weliaz :-).

5 Years
Discussion Span
Last Post by Weliaz

Try one of these

        Dim Request As System.Net.WebRequest
        Dim Response As System.Net.WebResponse
        Dim FileSize As Integer

        Request = Net.WebRequest.Create("http://www.??")
        Request.Method = Net.WebRequestMethods.Http.Get

        Response = Request.GetResponse

        FileSize = Response.ContentLength

        Dim FtpRequest As Net.FtpWebRequest
        Dim FtpResponse As Net.FtpWebResponse

        FtpRequest = Net.FtpWebRequest.Create("ftp://www.??")

        FtpRequest.Method = Net.WebRequestMethods.Ftp.GetFileSize

        FtpResponse = FtpRequest.GetResponse

        FileSize = FtpResponse.ContentLength

Just think i will need to notice about this:

File is not gonna be downloaded before it finds file size, it shouldn't take like 2 minutes to get file size of a 200MB file.

File is gonna be downloaded from a HTTP server, so is it possible to get the headers or anything?


On the http example above, change :

Request.Method = Net.WebRequestMethods.Http.Head
Request.Method = "Head"

That should do it.

Votes + Comments
ty so mucch =D
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.