[How Do I:] Export Data to a Comma Delimited (CSV) File for an Application Like Excel
by Chris Pels
In this video Chris Pels shows how to take data from a database or other source and export it to a comma delimited file that can be used in an application like Excel. First, a set of data is created as a DataTable object. Next, the Response for the current web page request is cleared and the header and content type are configured to be a csv file. Then the actual data is added to the response stream by first writing the column headers for the csv file followed by the data values. This approach can be useful when users require an export of data so it can be manipulated locally in a program like Excel.