How do you check a file type when there is no extension in c#

12,478

Solution 1

I've heard of reading the first few bytes of a file's contents and making an educated guess at the file's format. This link seems promising:

Using .NET, how can you find the mime type of a file based on the file signature not the extension

Solution 2

I had played this utility (TrID - File Identifier) and seems quite accurate. File type defination package (TrIDDefs) is also up to date.

And Here is a list of file type signature table if you interest. The list is continuing work-in-process.

Share:
12,478

Related videos on Youtube

Thomas07vt
Author by

Thomas07vt

Updated on June 04, 2022

Comments

  • Thomas07vt
    Thomas07vt almost 2 years

    How do you check a file type when there is no extension in c#

    For instance, I have files with no extension, that are either .mp4 or .flv format (just no extension). I plan on converting these video files to audio files however I would like to determine the file type before I start converting it. Is there a way to do this in C#?

    I was thinking that maybe I could just rename the file to name.mp4, then perform some task on the file that would either A) succeed, meaning that the file was indeed .mp4, or B) fail, in which case I could then rename it to .flv

    then convert the file as the appropriate extension. Is there a native process in c# that can look at .mp4 properties or .flv properties? I do not want to rename the file to .mp4 and then open it in a third party application, such as Windows Media Player, in order to see if I named it correctly.

  • Thomas07vt
    Thomas07vt about 12 years
    Thanks! that is just what i want. its hard to find something when you dont know enough to do a proper keyword search lol