Asp.net 如何命名Firefox上下载的文件?

Asp.net 如何命名Firefox上下载的文件?,asp.net,asp.net-mvc,http,firefox,attachment,Asp.net,Asp.net Mvc,Http,Firefox,Attachment,以下标题适用于IE,但不适用于FF <%@ Page Language="C#" ContentType="text/csv" Inherits="System.Web.Mvc.ViewPage"%> <% Response.AddHeader("Content-Disposition", "filename=report.csv;attachment"); %> 在FF中,FF中的建议名称显示为“report”,不带扩展名。请尝试“attachment;filen

以下标题适用于IE,但不适用于FF

<%@ Page Language="C#" ContentType="text/csv" Inherits="System.Web.Mvc.ViewPage"%>
<% Response.AddHeader("Content-Disposition", "filename=report.csv;attachment"); %>


在FF中,FF中的建议名称显示为“report”,不带扩展名。

请尝试“attachment;filename=\“report.csv\”
(即带引号的文件名)

文件名
只是的一个参数。因此,您必须交换这两个:

<% Response.AddHeader("Content-Disposition", "attachment;filename=report.csv"); %>


当我需要实现CSV生成和下载时,这个关于CSV生成的问题帮助了我:

我目前使用的代码如下所示:

response.AddHeader("Content-Disposition", "attachment; filename=\"data.csv\"");

在我的日常工作中——这很好。另外,您确定这不是您的操作系统或任何启用了“隐藏已知文件类型的扩展名”选项的操作系统吗?(我知道Windows有这个选项,这让我发疯)

最近我也遇到了这个问题,终于找到了解决方案

要使其在firefox中正常工作,请确保文件名中的引号放置正确,并且文件名中没有空格

这就是做基本测试的示例

这将起作用:

Response.ClearContent();
Response.ContentType = "text/csv";
Response.AddHeader("Content-Disposition", "attachment;filename="+ "MyOrders"+ "_Date_"
+DateTime.Now.ToString("d")+".csv");
这也将起作用

string myfilename = "MyOrders" + "_Date_" + DateTime.Now.ToString("d") + ".csv";
Response.AppendHeader("Content-Disposition", string.Format("attachment;filename={0}", 
myfilename));

//here you can check using the break point,weather you are using any extra quotes in filename
这在firefox中不起作用

Response.AddHeader("Content-Disposition", "attachment;filename="+ "MyOrders"+ "_Date_"
+DateTime.Now+".csv");

// because in DateTime.Now there is spaces in Time, Seconds , so firefox downloads file not 
//as csv but downloads it as File , may be a binary file or unknown file type
使用的参考资料,以及

感谢所有的人,他们的帖子在某种程度上帮助了我


希望它能帮助某人。

可能是因为他链接了文档,idk。。。我认为解决方案是使用引号(转义),但我真的不知道-我发布了这篇文章,因为我知道它对我有用,我没有文档链接或任何东西,因为它是我几个月前创建的代码,从那以后一直在使用,没有任何问题。谢谢你的帖子,它帮助解决了firefox的一个问题是解决方案