Click here to Skip to main content
15,891,607 members
Home / Discussions / C#
   

C#

 
GeneralRe: get the file type of a file Pin
aleroot5-Apr-10 7:15
aleroot5-Apr-10 7:15 
GeneralRe: get the file type of a file [modified] Pin
harold aptroot5-Apr-10 7:19
harold aptroot5-Apr-10 7:19 
GeneralRe: get the file type of a file Pin
harold aptroot5-Apr-10 12:45
harold aptroot5-Apr-10 12:45 
GeneralRe: get the file type of a file Pin
Dave Kreskowiak5-Apr-10 7:54
mveDave Kreskowiak5-Apr-10 7:54 
GeneralRe: get the file type of a file Pin
PIEBALDconsult5-Apr-10 8:48
mvePIEBALDconsult5-Apr-10 8:48 
GeneralRe: get the file type of a file Pin
Dave Kreskowiak5-Apr-10 10:19
mveDave Kreskowiak5-Apr-10 10:19 
GeneralRe: get the file type of a file Pin
PIEBALDconsult5-Apr-10 12:02
mvePIEBALDconsult5-Apr-10 12:02 
AnswerRe: get the file type of a file Pin
harold aptroot5-Apr-10 5:11
harold aptroot5-Apr-10 5:11 
That is not in general possible, you can at best make a "pretty good guess".
For example you can first check whether the file is a valid UTF-8 string, if the file is sufficiently big the chance is very small that a non-text file is accidentally valid UTF-8.
But you can't be quite sure, an invalid UTF-8 string could be made invalid because it is slightly corrupted or badly encoded and still "be"* text, and a binary file could accidentally (although the chance is quite small) be valid UTF-8.
Btw, ASCII files will validate as valid UTF-8.

And you could add some other things, such as checking for a byte order mark and/or UTF-16

* let's not argue about the meaning of "being a text file", but there are several ways to look at it, for example "if it can be decoded to text, it is a text file regardless of whether the text is meaningful" or "if and only if it was originally written as a text file, it is a text file"

If you know the text is going to be in a particular language you have some more options, such as checking the statistical properties of the text against expected values based on the language - that is still no sure-fire way to know whether something is actually text or even to reject all non-text, though.

No matter what you do with the result of the "text test", it had better be robust enough to handle "accidental non-text", and having a "I am sure this is text, do it anyway" option may be useful too.
GeneralRe: get the file type of a file Pin
PIEBALDconsult5-Apr-10 9:29
mvePIEBALDconsult5-Apr-10 9:29 
GeneralRe: get the file type of a file Pin
harold aptroot5-Apr-10 12:35
harold aptroot5-Apr-10 12:35 
AnswerRe: get the file type of a file Pin
AspDotNetDev5-Apr-10 11:40
protectorAspDotNetDev5-Apr-10 11:40 
QuestionIs there any lnk parser in C#? Pin
newcoder19995-Apr-10 4:07
newcoder19995-Apr-10 4:07 
QuestionWhite Flicker When Observing an Application Using Double Buffer Over RDP Pin
Catfish5405-Apr-10 3:33
Catfish5405-Apr-10 3:33 
QuestionFileSystemWatcher HELP PLEASE !! Pin
Rikq4-Apr-10 21:21
Rikq4-Apr-10 21:21 
AnswerRe: FileSystemWatcher HELP PLEASE !! Pin
OriginalGriff4-Apr-10 21:54
mveOriginalGriff4-Apr-10 21:54 
AnswerRe: FileSystemWatcher HELP PLEASE !! Pin
FyreWyrm5-Apr-10 16:12
FyreWyrm5-Apr-10 16:12 
QuestionHow to send Email in C# through the Exchange Server? Pin
ravis194-Apr-10 21:00
ravis194-Apr-10 21:00 
AnswerRe: How to send Email in C# through the Exchange Server? Pin
Abhinav S4-Apr-10 21:49
Abhinav S4-Apr-10 21:49 
QuestionHow to ATL COM exe(out-of-proc) in .net? Pin
SRKSHOME4-Apr-10 20:32
SRKSHOME4-Apr-10 20:32 
QuestionWindows Service service Account = Network Pin
yadlaprasad4-Apr-10 20:18
yadlaprasad4-Apr-10 20:18 
AnswerRe: Windows Service service Account = Network Pin
Dave Kreskowiak5-Apr-10 1:53
mveDave Kreskowiak5-Apr-10 1:53 
AnswerRe: Windows Service service Account = Network Pin
PIEBALDconsult5-Apr-10 3:38
mvePIEBALDconsult5-Apr-10 3:38 
Questioniteration Pin
adrian5644-Apr-10 19:34
adrian5644-Apr-10 19:34 
AnswerRe: iteration Pin
Abhinav S4-Apr-10 19:51
Abhinav S4-Apr-10 19:51 
GeneralRe: iteration Pin
adrian5644-Apr-10 19:55
adrian5644-Apr-10 19:55 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.