- My team working asp.net File manage project
- In our project we need to export database contents to csv formats
- The Database table contains 6 fields
- We are using LINQ.
views:
47answers:
1
+2
A:
I'd not advice to load all 1,00,000 record in memory and let it all download at once as csv. Converting database records to CSV format should not be a problem though as it will just be matter of string manipulation. In your asp.net application you can put a button "Download as CSV", clicking on which you'll start reading data in batch of say 1,000 records convert the batch to csv and put it in response buffer and flush the response stream while you read the next batch of 1,000 records. You will want to prompt the download dialog at client for which you can add below mentioned response header before first batch of records are flushed to client.
/// <summary>
/// Displays download file dialog.
/// </summary>
protected void DownloadAsCsv()
{
Response.Clear();
Response.AddHeader("content-disposition", string.Format("attachment; filename={0}", "your-filename.csv"));
Response.ContentType = "application/octet-stream";
//start flushing records to CSV in batch here..
}
this. __curious_geek
2010-06-03 05:03:52
Would be much easier to set [Response.BufferOutput](http://msdn.microsoft.com/en-us/library/system.web.httpresponse.bufferoutput.aspx) to false instead of repeatedly flushing it.
hemp
2010-06-03 05:36:04