Hello friends we all go for a complex coding for exporting the data into excel sheet. Some times we face a problem that we are not having the interop dll for export to excel. So here is a solution for all of us which will help in exporting the data into .csv format.
Using the code
Here is a simple code.
var lines = new List<string>();
string columnNames = dataTable.Columns.Cast<datacolumn>().
Select(column => column.ColumnName).
var header = string.Join(",", columnNames);
var valueLines = dt.AsEnumerable()
.Select(row => string.Join(",", row.ItemArray));
This is the most simplest code that i have used. You all will also find this interesting.