<p>How do you go about verifying the type of an uploaded file reliably without using the extension? I'm guessing that you have to examine the header / read some of the bytes, but I really have no idea how to go about it. Im using c# and asp.net.</p>

<p>Thanks for any advice.</p>

<hr>

<p>ok, so from the above links I now know that I am looking for 'ff d8 ff e0' to positively identify a .jpg file for example.</p>

<p>In my code I can read the first twenty bytes no problem:</p>

<pre><code>                FileStream fs = File.Open(filePath, FileMode.Open);
                Byte[] b = new byte[20];
                fs.Read(b, 0, 20);
</code></pre>

<p>so (and please excuse my total inexperience here) but how do I check whether the byte array contains 'ff d8 ff e0'?</p>

The first few bytes of a file will often tell you the file type.  See, for example,
http://www.garykessler.net/library/file_sigs.html
http://www.astro.keele.ac.uk/oldusers/rno/Computing/File_magic.html
Use System.IO to read the byes as binary after the upload.
I'm curious, though, why you can't rely on on the ContentType header?