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

前端 未结 6 422
情书的邮戳
情书的邮戳 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 06:47

    Oh, that is not bad. In your ASPX page's Page_Load do this:

    Response.ContentType = "text/xml";
    Response.ContentEncoding = System.Text.Encoding.UTF8;
    Response.Write(/* your text goes here */);
    

    The above is an example if your 'file' is xml, but it can be anything, from and excel file to a pdf. All you have to do is update the ContentType which you can lookup via Google or Live.

提交回复
热议问题