views:

141

answers:

1

I have a link to two files, they may be the same file but they may not be the same URL. I want to figure out if they are the same by checking the content-length before doing a full download. Whats the best way to do this? Currently i am using webbrowser control to load the page and extract data then using WebClient.Download to get the file. If there a way i can use WebClient to check the filesize before DLing the entire file?

+3  A: 

Equality of lengths does not mean that files are identical. However, if you're sure that this is enough to assert equality, you can issue a HttpWebRequest with Method set to HEAD: this will only download file headers, including content-length.

Anton Gogolev
assuming that the content-length header gets set which may vary depending on the web server and whether any server side code is involved in the downloading
RobV
HEAD requests are SUPPOSED to be processed the same as normal, then have the body discarded... But you're right, some systems are probably lazy.
Matthew Scharley