Click here to Skip to main content
15,891,136 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am downloading image files from web using the following code in my Console Application.

C#
WebClient client = new WebClient();
client.DownloadFile(string address_of_image_file,string filename);


The code is running absolutely fine.
I want to know if there is a way i can get the size of this image file before I download it.
Posted
Updated 22-Aug-12 9:08am
v2

1 solution

From this source Get file size before downloading using webclient[^]:

You can use the ResponseHeaders Property[^] of the WebClient[^] to request the "Content-Length".

Quote:
C#
WebClient client = new WebClient();
client.OpenRead("address_of_image_file");
Int64 bytes_total= Convert.ToInt64(client.ResponseHeaders["Content-Length"]);
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900