Is this possible?
My issue revolves around the fact that the file I'm reading and trying to modify has a format completely outside my control (comes from a banking institution). They have decided to have a set of two columns repeat 3 times without changing the header
name, something like:
RecordId EmployeeID col1 col2 col1 col2 col1 col2
So, I can easily read this into a collection that allows me to iterate and view/display the contents by simply not reading the header record. However, the DataRecords are read-only so I cannot modify the collection of DataRecords and then pass it to
the WriteDataRecords() method of the CsvWriter, as I had hoped to do. All the modification will be programmatic with the user basically choosing a .CSV file and clicking 'Go' so the UI really doesn't matter (and I could use WinForms, but I usually prefer
I guess my question is, is there any easy/quick way for me to perform the following functionality: read in a CSV file, update the 7th column of every row to be 50, save it to a new file (or over top the old if that's possible, doesn't matter for this example).
Below is most of the code for my failed attempt:
It fails on the line that assigns "50" to the 7th column of the record. You make reference to the 'Item' property on a DataRecord but I've not yet found out how to get to that.
public partial class Window1 : Window
private ICollection<DataRecord> records;
private string filename;
//removed for example because it was using a file dialog, etc.
filename="a path to a known csv file";
private void saveCSV()
CsvWriter writer = new CsvWriter(filename);
private void modifyCSV()
foreach (DataRecord record in records)
record = "50";
private void loadCSV()
CsvReader reader = new CsvReader(newFn);
records = reader.ReadDataRecords();
private void btnOpen_Click(object sender, RoutedEventArgs e)
Another thing I tried that I won't detail here is using the CsvReader to fill a DataTable, but you cannot do that without a header record hence the wording of my question. Any suggestions?