ASP.NET how to check type of the file type irrespective of extension
<p>If somebody renames the extension of any file (other than excel) to xls and xlsx (please dont ask me why :-( ), I need to check for its validity (if that is still a valid excel file). I am using mime type and Its not working. Am I missing anything?</p>

<pre><code>const string excel2007MimeType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
const string excel2003MimeType = "application/vnd.ms-excel";

  string excelExtention = string.Empty;
            excelExtention = System.IO.Path.GetExtension(myFilePath.PostedFile.FileName).ToLower();
            string mimeType = myFilePath.PostedFile.ContentType;
            Response.Write("mime type" + mimeType + Environment.NewLine);
            if( 
                 (
                    !(excelExtention == ".xls" &amp;&amp; mimeType == excel2003MimeType)
                    ||
                    !(excelExtention == ".xlsx" &amp;&amp; mimeType == excel2007MimeType)
                 )
              )
            {
                Response.Write ("only excel file is permitted");
            }
</code></pre>

<p>I rename a jpg file to xlsx file and upload. If I print out variable mimetype, Its value is "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet". I am not sure why because the content is not an excel file. Its an image.</p>
