-
-
Notifications
You must be signed in to change notification settings - Fork 1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Can we add new row into existing CSV file without header. #1104
Comments
Is there any inbuilt method which I can use? |
You would have to read the file then write it again. The reader and writer are forward only. There's no way to edit a file. You can one file and write to another at the same time though, then delete the old file when done. |
Ok. thanks for your valuable response |
I have been able to append to a file without repeating the header row:
Note: make sure you build each record in the recordsToWrite collection the same way to avoid column mismatches |
I want to append a record to an existing CSV file so the header is already available. I want to just append a new record into existing CVS file.
Following is my code.
string filePath = "C:\Users\dushyant.patel\Desktop\ExportUtility\123.csv";
StreamWriter writer = new StreamWriter(filePath, true);
SharedDataModel model = new SharedDataModel();
model.SrNo = "17";
model.TypeofEvidence = "Video";
var csv = new CsvWriter(writer);
var record = new List { model };
csv.WriteRecords(record);
writer.Close();
return View();
The text was updated successfully, but these errors were encountered: