+1  A: 

Whatever the user renames the file extension to, that is the real file extension.

You should never depend on the file extension to tell you what's in the file, since it can be renamed.

See "how can we check file types before uploading them in asp.net?"

John Saunders
+1  A: 

You seem to be asking if you can identify file-type from its content.

Most solutions will indeed attempt the file extension, but there are too many different possible file types to be reliably identifiable.

Most approaches use the first several bytes of the file to determine what they are.

Here is one list, here another.

If you are only worried about text vs binary, see this SO question and answers.

See this SO answer for checking if a file is a JPG - this approach can be extended to use other file headers as in the first two links in this answer.

Oded
+1  A: 

There's no way to get the 'real' file extension - the file extension that you get from the filename is the real one. If file content is your concern, you can retrieve the content type using the .ContentType property and verify that it is a content type that you are expecting - eg. image/jpg.

Mun