Monthly Archives: November 2011

C#

Get file size via HTTP

How to get file size with http-request ?

HttpWebRequest req = (HttpWebRequest)WebRequest.Create("http://example.com/");
req.Method = "HEAD";
HttpWebResponse resp = (HttpWebResponse)(req.GetResponse());
int len = resp.ContentLength;