Csvhelper: Encoding for CsvWriter no longer supported?

Created on 25 Oct 2017  路  1Comment  路  Source: JoshClose/CsvHelper

I've got the last stable Version from CsvHelper and I am missing the Encoding property:

CsvWriter csv = new CsvWriter(writer);
csv.Configuration.Encoding = Encoding.GetEncoding(1252);

WIth the CsvReader Class it's available...
Do I have to use the encoding differently now?

Jochen

Most helpful comment

That property is never used when writing. The only time it's used when reading is when you have Configuration.CountBytes turned on. The only reason it exists is because the reader/writer use TextReader and TextWriter and the encoding isn't available there.

If you want to use an encoding for reading and writing, you need to set it on the TextReader or TextWriter that you're using.

var stream = new MemoryStream();
var writer = new StreamWriter(stream, Encoding.UTF8);
var csv = new CsvWriter(writer);

>All comments

That property is never used when writing. The only time it's used when reading is when you have Configuration.CountBytes turned on. The only reason it exists is because the reader/writer use TextReader and TextWriter and the encoding isn't available there.

If you want to use an encoding for reading and writing, you need to set it on the TextReader or TextWriter that you're using.

var stream = new MemoryStream();
var writer = new StreamWriter(stream, Encoding.UTF8);
var csv = new CsvWriter(writer);
Was this page helpful?
0 / 5 - 0 ratings