响应内容类型为 CSV [英] Response Content type as CSV

查看:24
本文介绍了响应内容类型为 CSV的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在 HTTP 响应中发送一个 CSV 文件.如何将输出响应设置为 CSV 格式?

I need to send a CSV file in HTTP response. How can I set the output response as CSV format?

这不起作用:

Response.ContentType = "application/CSV";

推荐答案

使用 text/csv 是最合适的类型.

Using text/csv is the most appropriate type.

您还应该考虑向响应添加 Content-Disposition 标头.通常,文本/csv 将由 Internet Explorer 直接加载到 Excel 的托管实例中.这可能是也可能不是理想的结果.

You should also consider adding a Content-Disposition header to the response. Often a text/csv will be loaded by a Internet Explorer directly into a hosted instance of Excel. This may or may not be a desirable result.

Response.AddHeader("Content-Disposition", "attachment;filename=myfilename.csv");

以上将导致出现一个文件另存为"对话框,这可能是您想要的.

The above will cause a file "Save as" dialog to appear which may be what you intend.

这篇关于响应内容类型为 CSV的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆