In ASP.NET, how to get the browser to download string content into a file? (C#)

前端 未结 6 465
情书的邮戳
情书的邮戳 2021-01-13 06:27

I would like to create a text file for export/download, like a *.csv, from an ASP.NET application. I know about Response.TransmitFile, but I want to do this without creating

6条回答
  •  天命终不由人
    2021-01-13 07:04

    Try this sample:

    protected void Button1_Click(object sender, EventArgs e)
    {
         Response.ContentType = "text/csv";
         Response.AddHeader("content-disposition", "attachment; filename=download.csv");
         Response.Write("your,csv,file,contents");
         Response.End();
    }
    

提交回复
热议问题