Csvhelper: Support for appending new record to the existing file

Created on 4 Oct 2013  路  4Comments  路  Source: JoshClose/CsvHelper

Current WriteRecord/WriteRecords methods overwrite existing records.
No support for appending new record to the existing file.

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 a TextReader/TextWriter and doesn't know anything about files.

All 4 comments

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(...).

Was this page helpful?
0 / 5 - 0 ratings

Related issues

CallMeBruce picture CallMeBruce  路  4Comments

mabead picture mabead  路  3Comments

shinriyo picture shinriyo  路  6Comments

malinru picture malinru  路  5Comments

RizwanAhmedJutt picture RizwanAhmedJutt  路  5Comments