Current WriteRecord/WriteRecords methods overwrite existing records.
No support for appending new record to the existing file.
When you open the file, either open in append mode, or open and seek to the end of the file. You can do this all via the FileStream
. CsvHelper takes in a TextReader/TextWriter
and doesn't know anything about files.
Just thought I'd mention a detail about this: where it's complicated is when there's a header for a CSV you're writing. That's the situation where having some real 'append' logic would help. However, I'm not sure where that responsibility would lie.
So you're appending and you have headers, so it writes the header again? Does turning headers off for writing not work in that situation?
Yeah, the way I was going to resolve was to actually set it via some logic at runtime with an if-check on File.Exists(...)
.
Most helpful comment
When you open the file, either open in append mode, or open and seek to the end of the file. You can do this all via the
FileStream
. CsvHelper takes in aTextReader/TextWriter
and doesn't know anything about files.