gpt4 book ai didi

.net - 在 .net 网站中生成文本文件的最佳方法是什么?

转载 作者:行者123 更新时间:2023-12-01 08:21:06 24 4
gpt4 key购买 nike

我的 vb.net Web 应用程序中有一个页面,需要将一堆数据放入文本文件中,然后将其呈现给用户以供下载。在 .net Web 服务器上构建此类文本文件的最佳/最有效方法是什么?

编辑:要回答下面的问题,这将是一次下载然后丢弃的文件。

更新:我将 John Rudy 和 DavidK 的建议粘合在一起,效果很好。谢谢大家!

最佳答案

使用 StringBuilder 创建文件的文本,然后使用 Content-Disposition 将其发送给用户。

在这里找到的例子:
http://www.eggheadcafe.com/community/aspnet/17/76432/use-the-contentdispositi.aspx

private void Button1_Click(object sender, System.EventArgs e)
{
StringBuilder output = new StringBuilder;
//populate output with the string content
String fileName = "textfile.txt";

Response.ContentType = "application/octet-stream";
Response.AddHeader("Content-Disposition", "attachment; filename=" + fileName);
Response.WriteFile(output.ToString());

}

关于.net - 在 .net 网站中生成文本文件的最佳方法是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/129927/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com