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 :-).

Recommended Answers

All 4 Replies

Member Avatar

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?

Member Avatar

On the http example above, change :

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

That should do it.

commented: ty so mucch =D +0
commented: :) +15

Worked out, ty a lot =D

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.