Err_Response_Headers_Multiple_Content_Disposition
<p>I have a requirement to export 2 <strong>csv</strong> files on a single button click. Below is my code to generate 2 <strong>csv</strong> files:</p>
<pre><code>using System.Data;
using System.Data.SqlClient;
using System.Text;
using System.IO;
using System;
using System.Configuration;
using System.IO.Packaging;
using System.Web;

namespace ExportToCsv
{
    public partial class WebForm1 : System.Web.UI.Page
    {
        //Build the CSV file data as a Comma separated string.
        string csvHeader = string.Empty;
        //Build the CSV file data as a Comma separated string.
        string csvDetails = string.Empty;    

        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void ExportCSV(object sender, EventArgs e)
        {
            string constr = ConfigurationManager.ConnectionStrings[&quot;ConStr&quot;].ConnectionString;
            using (SqlConnection con = new SqlConnection(constr))
            {
                using (SqlCommand cmd = new SqlCommand(&quot;select * from mytable-1&quot;)
                {
                    using (SqlDataAdapter sda = new SqlDataAdapter())
                    {
                        cmd.Connection = con;
                        sda.SelectCommand = cmd;
                        using (DataTable dt = new DataTable())
                        {
                            sda.Fill(dt);

                           
                            //foreach (DataRow rows in dt.Rows)
                            //{
                                foreach (DataColumn column in dt.Columns)
                                {
                                    //Add the Header row for CSV file.
                                    csvHeader += column.ColumnName + ' ';
                                }


                                //Add new line.
                                csvHeader += &quot;\r\n&quot;;

                                foreach (DataRow row in dt.Rows)
                                {
                                    foreach (DataColumn column in dt.Columns)
                                    {
                                        //Add the Data rows.
                                        csvHeader += row[column.ColumnName].ToString().Replace(&quot;,&quot;, &quot;;&quot;) + ' ';
                                    }

                                    //Add new line.
                                    csvHeader += &quot;\r\n&quot;;
                                }
                            //}

                                Response.Clear();
                                Response.Buffer = true;
                                Response.AddHeader(&quot;content-disposition&quot;, &quot;attachment;filename=HeaderSection.txt&quot;);
                                Response.Charset = &quot;&quot;;
                                Response.ContentType = &quot;application/text&quot;;
                                Response.Output.Write(csvHeader);                                                    
                        }
                    }              
                }

                using (SqlCommand cmd = new SqlCommand(&quot;select * from mytable-2&quot;)
                {
                    using (SqlDataAdapter sda = new SqlDataAdapter())
                    {
                        cmd.Connection = con;
                        sda.SelectCommand = cmd;
                        using (DataTable dt = new DataTable())
                        {
                            sda.Fill(dt);

                            
                            //foreach (DataRow rows in dt.Rows)
                            //{
                            foreach (DataColumn column in dt.Columns)
                            {
                                //Add the Header row for CSV file.
                                csvDetails += column.ColumnName + ' ';
                            }


                            //Add new line.
                            csvDetails += &quot;\r\n&quot;;

                            foreach (DataRow row in dt.Rows)
                            {
                                foreach (DataColumn column in dt.Columns)
                                {
                                    //Add the Data rows.
                                    csvDetails += row[column.ColumnName].ToString().Replace(&quot;,&quot;, &quot;;&quot;) + ' ';
                                }

                                //Add new line.
                                csvDetails += &quot;\r\n&quot;;
                            }
                            //}

                            // Download the CSV file.
                            Response.Clear();
                            Response.Buffer = true;
                            Response.AddHeader(&quot;content-disposition&quot;, &quot;attachment;filename=DetailSection.txt&quot;);
                            Response.Charset = &quot;&quot;;
                            Response.ContentType = &quot;application/text&quot;;
                            Response.Output.Write(csvDetails);
                            Response.Flush();
                            Response.End();
                        }
                    }
                }
            }

        }       
    }
}
</code></pre>
<p>I am getting the data from 2 different tables and export the data in csv seperately. If I remove the second <code>using</code> statement the functions works prefect but as I added the second <code>using</code> statement to write second csv my browser(<strong>Chrome</strong>) gives the error <code>Err_Response_Headers_Multiple_Content_Disposition</code></p>
<p>Please help.</p>