Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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? :(

  • Administrators
Posted

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.

Posting Guidelines FAQ Post Formatting

 

Intellectuals solve problems; geniuses prevent them.

-- Albert Einstein

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...