WebRequest: only get info about file, not download the file?

  • Thread starter =?ISO-8859-15?Q?Roland_M=FCller?=
  • Start date
?

=?ISO-8859-15?Q?Roland_M=FCller?=

Hello Group,

i want to get the file size of some files located on a webserver,
therefore i create a WebRequest with the URI of the file and then a
WebResponse on the WebRequest to get the ContentLength:


WebRequest webRequest = HttpWebRequest.Create(fileUri);
webRequest.Method = "HEAD"; //??????? (*)
WebResponse webResponse = webRequest.GetResponse();
fileSizeBytes = (ulong)webResponse.ContentLength;


(*) Does this setting make the WebRequest only send the info and not the
complete file?

I ask because i don't want to download large files completely only to
get the filename.

Thank you very much in advance,
Roland
 
J

Joerg Jooss

Thus wrote Roland,
Hello Group,

i want to get the file size of some files located on a webserver,
therefore i create a WebRequest with the URI of the file and then a
WebResponse on the WebRequest to get the ContentLength:

WebRequest webRequest = HttpWebRequest.Create(fileUri);
webRequest.Method = "HEAD"; //??????? (*)
WebResponse webResponse = webRequest.GetResponse();
fileSizeBytes = (ulong)webResponse.ContentLength;
(*) Does this setting make the WebRequest only send the info and not
the complete file?

WebRequest is a, um, request ;-)
The file will be part of the response.
I ask because i don't want to download large files completely only to
get the filename.

A HEAD request is similar to a GET request, but the server will not send
a HTTP body, only the headers. If these headers contain Content-Length, you'll
get what you need.

Cheers,
 
?

=?ISO-8859-15?Q?Roland_M=FCller?=

Thanks Joerg, i did analyze it with a network trace tool and it does
exactly what i want.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top