Detect File Type

ADO DOT NET

Well-known member
Joined
Dec 20, 2006
Messages
156
Hi,
I searched in MSDN before this post but I didnt find how should I detect the file that my user opened is a BINARY file or not?
I dont want to check the file extension, but I should read some header of file to see if its written in BINARY format or not?
I cannot find a .NET method to detect it? :(
 
By binary to you mean non-text or some (any?) specific binary file type?

Is there a reason why you dont want to use the extension to determine the file type?

The one fundamental problem you will encounter is that ultimately files are just bytes on disk and as far as the file system and the file IO routines are concerned there is no difference.

You could scan the files looking for bytes with a value larger than 127 and hope it isnt a text file using an ANSI code page that does have characters in the 128 - 255 range or a Unicode file... You could search the file and try to match known headers (http://www.wotsit.org/ is worth a look if this seems a good route to take) however there are probably thousands of file formats with potentially more being added every day.

It might be easier if you gave a bit of detail about what you are trying to do.
 
Back
Top