Nick,
In addition to the other comments:
Read the help for StreamReader(path,detectEncodingFromByteOrderMarks )
closer. ;-)
"The detectEncodingFromByteOrderMarks parameter detects the
encoding by looking at the first three bytes of the stream. It
automatically recognizes UTF-8, little-endian Unicode, and
big-endian Unicode text if the file starts with the appropriate
byte order marks. Otherwise, the user-provided encoding is used.
See the Encoding.GetPreamble method for more information."
Remember that if you do not call the constructor of StreamReader with an
Encoding object that UTF8Encoding is used. I would expect the same rule to
apply here. In other words Encoding.Default is not considered unless you
pass it to the constructor.
Ergo your code always returns a Unicode encoding.
Have you tried the StreamReader(path,encoding,
detectEncodingFromByteOrderMarks) constructor?
Hope this helps
Jay
"Nick" <ni*****@heha.net.tw> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
Hi,
I have used the following code to test the encoding of a file :
public string DetermineFileType(string aFileName)
{
string sEncoding = string.Empty;
StreamReader oSR = new StreamReader(aFileName, true);
oSR.ReadToEnd(); // Add this line to read the file.
sEncoding = oSR.CurrentEncoding.EncodingName;
return sEncoding;
}
from:
http://groups.google.com.hk/groups?h...3DN%26tab%3Dwg
But the encoding is always showing Unicode? What's wrong?
Thanks
Nick