Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/silverlight/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 读取.csv文件时如何获取编码?_C#_Silverlight_Encoding_Csv_Openfiledialog - Fatal编程技术网

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

C# 读取.csv文件时如何获取编码?,c#,silverlight,encoding,csv,openfiledialog,C#,Silverlight,Encoding,Csv,Openfiledialog,作为标题,以下代码 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 == tru

作为标题,以下代码

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();
    }
}
有没有办法找到“_fInfo”当前编码?
PS:我使用了silverlight控制台(silverlight 2.0)。

在第一次读取后尝试StreamReader.CurrentEncoding。读者将尝试检测编码。

在谷歌上搜索
get file encoding c#
将返回许多代码示例。查看此链接:也可以尝试以下内容: