C# How to know the size of file on a website

cfilesize

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;

Best Answer

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