.CSV をダウンロードして、ユーザーを別のページにリダイレクトしたいと考えています。
これは私のコードです
protected void btnExport_Click(object sender, EventArgs e)
{
string attachment = "attachment; filename=" + Request.QueryString["exportName"] + ".csv";
HttpContext.Current.Response.Clear();
HttpContext.Current.Response.ClearHeaders();
HttpContext.Current.Response.AddHeader("content-disposition", attachment);
HttpContext.Current.Response.ContentType = "application/ms-excel";
//CODE TO WRITE CSV
List<Company> companies = (List<Company>)Session["SelectedCompanies"];
foreach (Company company in companies)
{
HttpContext.Current.Response.Write(company.Name + ";");
HttpContext.Current.Response.Write(Environment.NewLine);
}
HttpContext.Current.Response.Redirect("otherpage.aspx", true);
}
残念ながら、リダイレクトのみを行い、.CSV のダウンロードは行いません。
で置き換えると、.CSV のダウンロードのみが行わHttpContext.Current.Response.Redirect("otherpage.aspx", true);
れHttpContext.Current.Response.End();
、リダイレクトは行われません。
しかし、私は両方を持っていたいです。