I am using the StreamReader class in .NET as follows:
using( StreamReader reader = new StreamReader( "c:\somefile.html", true ) { string filetext = reader.ReadToEnd(); }
This works fine when there is a specification in the file. I ran into a problem with a file without specification. Mostly I got gibberish. When I specified Encoding.Unicode, it worked fine, for example:
using( StreamReader reader = new StreamReader( "c:\somefile.html", Encoding.Unicode, false ) { string filetext = reader.ReadToEnd(); }
So, I need to get the contents of the file into a string. So how do people usually deal with this? I know that there is no solution that will work in 100% of cases, but I would like to improve my chances. Obviously, there is software that is trying to guess (for example, notepad, browsers, etc.). Is there a way in the .NET Framework that will guess about me? Does anyone have code that they would like to share?
More background: This question is pretty much like mine, but I'm in .NET. This question led me to a blog listing various detection coding , but none of them are in .NET
user70602
source share