1

I want to download a file on a website using C# and show its downloading percentage using progressBar. I know I can use the following code to get the size of a local file, but how can I know the size of file posted on a website?

FileInfo finfo = new FileInfo(strFilePath);
int length = (int)finfo.Length;
Chilly Zhong
  • 16,763
  • 23
  • 77
  • 103
  • possible duplicate of [Get http:/.../File Size](http://stackoverflow.com/questions/122853/get-http-file-size) – stimms Mar 07 '14 at 16:07

1 Answers1

3

When you start the download, the server should send a Content-length header which will tell you how big the file is.

mopoke
  • 10,555
  • 1
  • 31
  • 31
  • 1
    Thanks. I write request.Method="HEAD" and now sucessfully use the key "Content-Length" in WebHeaderCollection to get the file size. – Chilly Zhong Jan 02 '10 at 06:11