0

I am reading a Csv file in a asp.net Web application to produce a report. The CsvReader element does not read in special characters such as ± or Σ.

            var avar = FileUploader.PostedFile.FileName;
            var myfile = File.OpenText(avar);
            CsvReader csv = new CsvReader(myfile);
            data = csv.GetRecords<T>().ToList();

The reader skips the special characters mentioned above. Every other characters is read included characters surrounding the special characters. Can anyone tell me how to fix this? Thanks.

nuDvlpr
  • 1
  • 2

1 Answers1

0

I use GetEncoding from this link Effective way to find any file's Encoding to find the encoding of my file.

then, I set the configurations:

CsvConfiguration config = new CsvConfiguration();
config.Delimiter = ",";
Encoding enc = GetEncoding(FileUploader.PostedFile.FileName);
config.Encoding = enc;
config.HasHeaderRecord = true;
config.QuoteNoFields = true;

Next, I use a FileStream to load file and send it to a StreamReader.

FileStream stream = File.OpenRead(FileUploader.PostedFile.FileName);
StreamReader reader = new StreamReader(stream, Encoding.GetEncoding(enc.HeaderName));
CsvReader csv = new CsvReader(reader, config);
datas = csv.GetRecords<T>().ToList();

All characters are readable when I load a file. is an IEnumerable class

Community
  • 1
  • 1
nuDvlpr
  • 1
  • 2