tags:

views:

470

answers:

4
A: 

If you don't have header then you can use "Microsoft.Office.Interop.Excel" DLL. To get the reference of this dll, use "Add Reference" and ".NET" tab.

You can you it to check each field value by looping and can update and delete , which is matched.

Deepak
Unfortunately I cannot have this "Microsoft.Office.Interop.Excel" DLL running on the production server.
Kojof
+1  A: 

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.

ck
Thanks for all the responses, this one was the closet to what i used.
Kojof
A: 

I would recommend the FileHelpers library, you can make simple classes which map to you file structure. This way you can have a strongly-typed representation of the file which is easy to edit and save again.

It's pretty fast too.

Robert Massa
+1  A: 

When you need to update CSV files, pretty much the only answer is to read the whole thing in, modify it and write it out again. Or if it's large, you interleave those operations one line at a time.

NXT