dcsimg
Login | Register   
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX

By submitting your information, you agree that devx.com may send you DevX offers via email, phone and text message, as well as email offers about other products and services that DevX believes may be of interest to you. DevX will process your information in accordance with the Quinstreet Privacy Policy.


Tip of the Day
Home » Tip Bank » .NET » C#
Language: .NET
Expertise: Intermediate
Jan 23, 2018

WEBINAR:

On-Demand

Building the Right Environment to Support AI, Machine Learning and Deep Learning


How to Find the Size of the HTTP Resource Being Fetched

There are cases in which we might want to warn the user before an attempt is made to download a large file, or we might simply be interested to know its size before downloading.

In C#, we use the HttpWebRequest class to download objects from an URL. We can set the request method to be of "Head" type and examine the response header "Content-Length" to determine the size of the object.

string url = "http://mydomain.com/FileStore/bigfile.zip";
var urlRequest = (HttpWebRequest)WebRequest.Create(url);
//Set the request.method to ???HEAD???
urlRequest.Method = "HEAD";

var urlResponse = urlRequest.GetResponse();
string contentLength = urlResponse.Headers.Get("Content-Length");
Messagebox.Show(int.Parse(contentLength).ToString());
Srinath M S
 
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap
Thanks for your registration, follow us on our social networks to keep up-to-date