0

The files you want to read can be in 2 different encodings, UTF-8 and Windows-1251. UTF-8 is normally recognized, but 1251 it cannot recognize correctly. What encoding of the file before it was processed is not known. What are the possible solutions?

        csvReaderConfig = new CsvConfiguration(CultureInfo.InvariantCulture)
        {
            Delimiter = ";",
            BadDataFound = null,
            MissingFieldFound = null,
            //Encoding = Encoding.GetEncoding(1251) //default utf-8
        };

        using (var reader = new StreamReader(path))
        {
            try
            {
                using (var csv = new CsvReader(reader, csvReaderConfig))
                {
                    records = csv.GetRecords<object>().ToList();
                }
            }
            catch (Exception ex)
            {

            }
        }
JonnyJon44
  • 73
  • 1
  • 11
  • 1
    What you're asking for is magic. So no. – Ian Kemp Sep 08 '21 at 18:05
  • 1
    Does this answer your question? [How to detect the character encoding of a text file?](https://stackoverflow.com/questions/4520184/how-to-detect-the-character-encoding-of-a-text-file) – GoWiser Sep 08 '21 at 18:37

0 Answers0