How can I check the file type if there is no extension in C #?

How to check file type if in C #

no extension?

For example, I have files with no extension, which are either .mp4 or .flv (no extension). I am planning on converting these video files to audio files, but I would like to determine the file type before starting converting it. Is there a way to do this in C #?

I thought that maybe I could just rename the file to name.mp4 and then do some task on the file, which is either A), which means the file was indeed .mp4, or B), in which case I could rename it to .flv

then convert the file to the appropriate extension. Is there a native process in C # that can view .mp4 properties or .flv properties? I don't want to rename the file to .mp4 and then open it in a third party application like Windows Media Player to see if I named it correctly.


source to share

2 answers

I have heard about reading the first few bytes of the contents of a file and generating in the file format. This link seems promising:

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



I've played this utility ( TrID - File ID ) and it seems pretty accurate. The file type protection package (TrIDDefs) has also been updated.

And Here is a list of file type signature tables if you're interested. The list continues in the process.



All Articles