tags:

views:

118

answers:

2

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;
+3  A: 

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

mopoke
Thanks. I write <code>request.Method="HEAD"</code> and now sucessfully use the key "Content-Length" in WebHeaderCollection to get the file size.
iPhoney
+1  A: 

Take a look at this question http://stackoverflow.com/questions/122853/c-get-http-file-size

stimms
Oh, I failed to find this similar post by myself. Thanks for giving me this link and I'm glad that I can figure it out now.
iPhoney