ADO DOT NET Posted December 10, 2007 Posted December 10, 2007 Hi, I searched in MSDN before this post but I didn't find how should I detect the file that my user opened is a BINARY file or not? I don't want to check the file extension, but I should read some header of file to see if it's written in BINARY format or not? I cannot find a .NET method to detect it? :( Quote
Administrators PlausiblyDamp Posted December 10, 2007 Administrators Posted December 10, 2007 By binary to you mean non-text or some (any?) specific binary file type? Is there a reason why you don't 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 isn't 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. Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.