Search code examples
c#.netwindowsfile-extensionfile-type

Is there an easy way to determine the type of a file without knowing the file's extension?


I have a table with a binary column which stores files of a number of different possible filetypes (PDF, BMP, JPEG, WAV, MP3, DOC, MPEG, AVI etc.), but no columns that store either the name or the type of the original file. Is there any easy way for me to process these rows and determine the type of each file stored in the binary column? Preferably it would be a utility that only reads the file headers, so that I don't have to fully extract each file to determine its type.

Clarification: I know that the approach here involves reading just the beginning of each file. I'm looking for a good resource (aka links) that can do this for me without too much fuss. Thanks.

Also, just C#/.NET on Windows, please. I'm not using Linux and can't use Cygwin (doesn't work on Windows CE, among other reasons).


Solution

  • Here are a few tools to find the format of a file:

    1. a website Online File Identifier: http://mark0.net/onlinetrid.aspx by Marco Pontello

    2. a software called File Analyzer by Vadim Tarasov.

    The website has the advantage not to require any installation, and thus is less likely to provide any malware. However, you have to upload your file, which might not be what you want for privacy.


    Here is an example with the save file of the game Pampas & Selene: The Maze of Demons Demo:

    Results obtained with the website

    The .sav file is identified as TIM (PlayStation graphics) .