Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Checking Download size before download

Tags:

c#

.net

asp.net

I need some way to check the size of a download without having to download the entire file. I am using C# and the System.Net.WebClient to do the downloads.The check needs to run in a asp.net webservice.

Thanks

like image 978
RC1140 Avatar asked Mar 18 '09 11:03

RC1140


People also ask

How do I know the size of a file before downloading?

you can get a header called Content-Length form the HTTP Response object that you get, this will give you the length of the file. you should note though, that some servers don't return that information, and the only way to know the actual size is to read everything from the response.

How do I check a files size?

Locate the file or folder whose size you would like to view. Click the file or folder. Press Command + I on your keyboard. A window opens and shows the size of the file or folder.

Why do you need to know the file size when you create download or save any files into your computer?

Every file on a computer uses a certain amount of resources when sent over the internet or stored. Keeping mind of your kilobytes (kB) and megabytes (MB) can prevent problems and produce a smoother online experience.


1 Answers

Use HTTP method HEAD to retrieve Content-Length: header.

HEAD / HTTP/1.1
Host: www.example.com

HTTP/1.1 200 OK
Date: Wed, 18 Mar 2009 11:21:51 GMT
Server: Apache/2.2.3 (CentOS)
Last-Modified: Tue, 15 Nov 2005 13:24:10 GMT
ETag: "b80f4-1b6-80bfd280"
Accept-Ranges: bytes
Content-Length: 438 
Connection: close
Content-Type: text/html; charset=UTF-8
like image 94
vartec Avatar answered Oct 12 '22 15:10

vartec