Search code examples
c#csvoledb

Update or Delete a Line from CSV using C#


can anyone please help me with this query.

I have a CSV file which is used by a unix application as a config file.

The file has no header and the first column is unique.

This is the format of the file.

XXX1,11112009,11112009
XXX2,11112009,11112009

How do i, using C#:

1) update a a whole line
2) Delete a line

I tried using OLEDB to update the file, but because there is no header,it's difficult to work with.

regards

K


Solution

  • Read the file lines into a String[] using File.ReadAllLines(path) then loop through and output as necessary.

    This will work up to a few hundred thousand lines.