export datatable to CSV with Save File Dialog box - C#
<p>Struggling to get my CSV export to display the Save File dialog box up.  It saves to file ok, but doesn't let the user save.  Can anybody see where I might be going wrong with the code please?</p>

<pre><code>string filename = Server.MapPath("~/download.csv");
StreamWriter sw = new StreamWriter(filename, false);

int iColCount = dt.Columns.Count;
for (int i = 0; i &lt; iColCount; i++)
{
    sw.Write(dt.Columns[i]);
    if (i &lt; iColCount - 1)
    {                
        sw.Write(",");
    }
}
sw.Write(sw.NewLine);

foreach (DataRow dr in dt.Rows)
{
    for (int i = 0; i &lt; iColCount; i++)
    {
        if (!Convert.IsDBNull(dr[i]))
        {
            sw.Write(dr[i].ToString());
        }
        if (i &lt; iColCount - 1)
        {
            sw.Write(",");
        }
    }
    sw.Write(sw.NewLine);
}
sw.Close();

Response.Clear();
Response.ContentType = "application/csv";
Response.AddHeader("Content-Disposition", "attachment; filename=download.csv");
Response.WriteFile(filename);
Response.Flush();
Response.End();
</code></pre>

<p>I thought the Content Disposition line that brought up the dialog box, but maybe there is something else I need to do.</p>

<p>Thanks</p>
