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

2

3

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.

Electrobiology answered 17/3, 2012 at 4:33 Comment(1)
How did this go wrong? Just ask whomever renamed the file to rename it back.Trichocyst
I
4

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

Interrupt answered 17/3, 2012 at 4:50 Comment(1)
Thanks! that is just what i want. its hard to find something when you dont know enough to do a proper keyword search lolElectrobiology
K
3

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.

Kate answered 17/3, 2012 at 5:59 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.