简体   繁体   English

读取.csv文件时如何获取编码?

[英]How to get encoding when I read a .csv File?

As title, the following code... 作为标题,下面的代码...

System.IO.FileInfo _fInfo;
OpenFileDialog openDlg = new OpenFileDialog();
openDlg.Filter = "Csv Files (.csv)|*.csv";
openDlg.FilterIndex = 1;
openDlg.Multiselect = false;
bool? userClickedOK = openDlg.ShowDialog();

if (userClickedOK == true)
{
    _fInfo = openDlg.File;
}
Stream fileStream = _fInfo.OpenRead();
using (System.IO.StreamReader reader = new StreamReader(fileStream))
{
    int lineNo = 1;
    while (!reader.EndOfStream)
    {
       reader.ReadLine();
    }
}

Is any way to find "_fInfo" current encoding? 有什么办法可以找到“ _fInfo”当前的编码? PS: I used silverlight console(silverlight 2.0). PS:我使用了silverlight控制台(silverlight 2.0)。

Try StreamReader.CurrentEncoding after first read. 首次读取后,尝试StreamReader.CurrentEncoding。 The reader will try to detect encoding. 读者将尝试检测编码。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM