Create text file and download

前端 未结 7 1104
日久生厌
日久生厌 2020-12-14 01:08

I\'m trying to write to a text file in memory and then download that file without saving the file to the hard disk. I\'m using the StringWriter to write the con

相关标签:
7条回答
  • 2020-12-14 01:54

    Basically you create an HttpHandler by implementing the IHttpHandler interface. In the ProcessRequest method you basically just write your text to context.Response. You also need to add a Content-Disposition http header:

    context.Response.AddHeader("Content-Disposition", "attachment; filename=YourFileName.txt");
    

    Also remember to set the ContentType:

    context.Response.ContentType = "text/plain";
    
    0 讨论(0)
提交回复
热议问题