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

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

问题描述

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

这是行不通的:

  Response.ContentType =应用程序/ CSV;


解决方案

使用文本/ CSV 是最合适的类型。

您也应该考虑增加一个内容处置头的响应。通常,一个文本/ CSV将由Internet Explorer中直接加载到Excel的托管实例。这可能是也可能不是一个理想的结果。

  Response.AddHeader(内容处置,附件;文件名= myfilename.csv);

以上会导致文件另存为对话框出现这可能是您想要的东西。

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

This is not working:

Response.ContentType = "application/CSV";

解决方案

Using text/csv is the most appropriate type.

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天全站免登陆