通过Response获取文件而不为其提供扩展名

时间:2011-09-12 20:33:17

标签: c# asp.net download

我有一个ASP.NET页面,用户可以单击按钮获取没有扩展名的文件。

string fileName = "ExtensionLessFileName";
Response.ContentType = "text/plain";
Response.AppendHeader("Content-Disposition", "attachment; filename=" + fileName);
Response.Write("the text content of hte file");
Response.End();

问题是我需要将下载的文件扩展为较少,但似乎不可能,因为浏览器“另存为”对话框迫使我将其设为txt。我评论了ContentType行,文件以html结尾。

感谢您帮助实现这一目标或理解为什么不可能。

1 个答案:

答案 0 :(得分:0)

尝试更改MIME类型。我建议

Response.ContentType = "application/unknown";

它适用于我的未知文件类型。

相关问题