C#

Creating Csv file from DataTable in C#

Note :This post is first published on Apr-2013 in my previous blog Techkindle. Moving the content to here.

Steps:

  1. Create a DataTable Schema.
  2. Fill the created table with some sample data.
  3. Create a StringBuilder, by appending all the data, (using comma delimiter)
    • Create one new line with data table columns.
    • Create one line for each data table row.
  4. Save the StringBuilder to Csv file, using FileStream.

Happy Coding :)

Share