Friday 20 March 2009

How to identify the encoding format of the text file?

When we reading data from ANSI formatted or Unicode formatted text file using OLEDB, the schema.ini file has to be changed accordingly to read data from the text file. The default format is UTF8. If the encoding format of the text file is “ANSI/UTF8”, we do not need to specify the character set in the schema.ini file. If the encoding format of the text file is “Unicode”, we should specify the characterset=Unicode in the schema.ini file to read the non-English characters.

How to identify or find the encoding format of a text file at runtime?

FileInfo file = new FileInfo(@"C:\TestFile.txt"); StreamReader streamReader = file.OpenText(); streamReader.ReadLine(); string encodingFormat = streamReader.CurrentEncoding.EncodingName;

If you use Quick Watch window in VS.Net 2005, you will see as below


No comments:

Post a Comment