c# - How to get the file size from http headers -


i want size of http:/.../file before download it. file can webpage, image, or media file. can done http headers? how download file http header?

yes, assuming http server you're talking supports/allows this:

system.net.webrequest req = system.net.httpwebrequest.create("http://stackoverflow.com/robots.txt"); req.method = "head"; using (system.net.webresponse resp = req.getresponse()) {     int contentlength;     if(int.tryparse(resp.headers.get("content-length"), out contentlength))     {          //do useful contentlength here      } } 

if using head method not allowed, or content-length header not present in server reply, way determine size of content on server download it. since not particularly reliable, servers include information.


Comments

Popular posts from this blog

c++ - How do I get a multi line tooltip in MFC -

asp.net - In javascript how to find the height and width -

c# - DataTable to EnumerableRowCollection -