Asp.net 创建制表符分隔的 txt 文件
我必须从查询创建一个制表符分隔的 txt 文件。 我想调用一个 HttpHandler 将我的 txt 文件作为流返回,我不想以物理方式创建该文件。
第一个问题: 从查询结果创建制表符分隔的 txt 文件的最佳实践是什么? 我必须获取所有行并手动创建文件?
第二个问题: 如何为创建文件的 HttpHandler 设置超时?
感谢您抽出时间。
I have to create a tab delimited txt file from a query.
I want to call an HttpHandler that returns my txt file as a stream, I don't want to create the file phisically.
1st question:
what is the best practice to create the tab delimited txt file from a query result?
I have to fetch all rows and create the file manually?
2nd question:
How to set a timeout for the HttpHandler that creates the file?
Thanks for your time.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我将创建一个普通的旧 http 输出流并将内容类型更改为“text/plain”,这意味着您不需要在 Web 服务器上物理创建文件,并且如果您添加内容处置标头到输出并指定它有一个名为“report.txt”之类的附件,系统将提示用户打开或保存内容,而不是像普通网页一样在浏览器中查看它。
您可以使用 Server.ScriptTimeout = x 通过访问当前 HttpContext 对象来设置脚本超时
希望这有帮助
I would create a plain old http output stream and change the content type to 'text/plain' which means that you don't need to physically create the file on the web server, and if you add the content-disposition header to the output and specify that it has an attachment called something like 'report.txt' the user will be prompted to Open or Save the content, rather than just viewing it in the browser like a normal web page.
You can use the Server.ScriptTimeout = x to set the script timeout by gaining access to the current HttpContext object
Hope this helps