CSV下载为HTM

use*_*569 5 c# csv asp.net web

我在所有浏览器中都遇到了很大的问题.

我有一个网站,客户可以下载包含所需详细信息的csv文件.

我遇到的问题是csv文件要么没有扩展名下载,要么下载为htm文件.

在我用.csv指定文件名的代码中,服务器上的文件也是.csv.

代码如下

context.Response.Buffer = true;
context.Response.Clear();
context.Response.ClearHeaders();                    
context.Response.ContentType = "text/csv";
context.Response.AppendHeader("Content-Disposition", @"attachment,     
     filename=" + ((string)Path.GetFileName(downloadFilePath)));
context.Response.WriteFile(downloadFilePath);
context.Response.Flush();
context.Response.Close();
Run Code Online (Sandbox Code Playgroud)

我曾尝试context.Response.ContentType = "text/html";context.Response.ContentType = "application/octet-stream";.

它在IIS6上运行.

有人知道是什么原因引起的吗?

use*_*569 0

好的,我已经弄清楚为什么文件没有以 CSV 格式下载。

这是因为文件名中有空格,所以我需要将文件名括起来,这样它就不会在空格处被截断。

谢谢你的帮助