【发布时间】:2013-12-16 13:02:17
【问题描述】:
我想在我的 MVC 控制器中下载一个格式未知的文件。
这是我的代码
公共静态无效下载附件(字符串名称,字符串物理路径) {
if (System.IO.File.Exists(physicalPath))
{
System.IO.FileInfo file = new System.IO.FileInfo(physicalPath);
byte[] fileB = File.ReadAllBytes(physicalPath);
HttpContext context = HttpContext.Current;
context.Response.ClearHeaders();
context.Response.Clear();
context.Response.AddHeader("content-disposition", "attachment; filename="+Name+";");
context.Response.ContentType = "application/force-download";
context.Response.BinaryWrite(fileB.ToArray());
context.Response.Flush();
context.Response.End();
}
}
但它不工作,但没有给出任何错误。
我该如何解决这个问题?
【问题讨论】:
-
它是否适用于 ContentType 的“application/octet-stream”?
标签: c# asp.net-mvc