Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I write CSV file with header using FileHelpers?

I am using FileHelpers to write DataTable content into CSV file.

Because of huge number of records in DataTable I chose to dump the result set as it is in DataTable into CSV file like below

CommonEngine.DataTableToCSV(dt, filename)

And the CSV has sucessfully written with 2 million records having the size of 150MB.

But I wanted to add the filed header at first line of this CSV file.

Is there a way FileHelper will allow to write the header using CommonEngine.DataTableToCSV?

like image 560
vijay Avatar asked Sep 12 '26 15:09

vijay


1 Answers

You must use engine.HeaderText = engine.GetFileHeader() before you call WriteFile

like image 144
Stefan Z Camilleri Avatar answered Sep 14 '26 06:09

Stefan Z Camilleri



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!