1

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? PS: I used silverlight console(silverlight 2.0).

Andre Calil
  • 7,652
  • 34
  • 41
user1531714
  • 111
  • 13
  • 1
    A simple google search for `get file encoding c#` would return many a code samples. – Cole Tobin Aug 17 '12 at 01:24
  • Take a look at this link: http://stackoverflow.com/questions/90838/how-can-i-detect-the-encoding-codepage-of-a-text-file – Guillaume Aug 17 '12 at 01:44
  • Try this also: http://stackoverflow.com/questions/1347088/c-is-there-any-way-to-discover-what-charset-encoding-a-file-is-using – Akira Yamamoto Aug 17 '12 at 03:26
  • 1
    @ColeTobin Funny, I did just that and ended up on this question of StackOverflow where the first comment tells me to "google it". Nice. – waka Jan 17 '23 at 13:36

1 Answers1

0

Try StreamReader.CurrentEncoding after first read. The reader will try to detect encoding.

Feng Yuan
  • 709
  • 5
  • 4