如何让特殊类型文件可以下载? 小弟网站中的常规文件比如.txt .exe .jpg等可以通过WebClient正常下载,但.bat文件和一种扩展名为.tvt的文件无法下载,提示404错误。请问如何在web.config中设置以使得这些特殊类型文件可以下载? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 试试以下的: string filePath = Server.MapPath("~/文件目录/文件名.doc"); FileStream fs = new FileStream(filePath, FileMode.Open); byte[] bytes = new byte[(int)fs.Length]; fs.Read(bytes, 0, bytes.Length); fs.Close(); Response.ContentType = "application/octet-stream";//通知浏览器下载文件而不是打开 Response.AddHeader("Content-Disposition", "attachment; filename=" + HttpUtility.UrlEncode("文件名.doc", System.Text.Encoding.UTF8)); Response.BinaryWrite(bytes); Response.Flush(); Response.End(); 不是程序的问题,IIS有限制。 压缩文件实现下载如System.Diagnostics.Process Process1 = new System.Diagnostics.Process(); Process1.StartInfo.FileName = "Winrar.exe"; Process1.StartInfo.CreateNoWindow = true;或输出二进制流数据 asp.net字幕滚动 请问UpdatePanel中可以更新文本框等,但无法更新Image RequiredFieldValidator控件问题 【ASP.net 连接SQL SERVER 2000 数据库 报错】~~~~~~~~~~~UP有分。国庆快乐 Excel的进程不能关闭 为什么数据不刷新? 急急~cs文件中javascript的写法~ 大家帮忙-在asp.ent web应用程序中怎么做webgis? 帮忙参考几本书 各位老哥,救命呀 如何布局在 EditItemTemplate中的控件 请朋友们给我点提高负载(并发?)的思路.问题如下!
string filePath = Server.MapPath("~/文件目录/文件名.doc");
FileStream fs = new FileStream(filePath, FileMode.Open);
byte[] bytes = new byte[(int)fs.Length];
fs.Read(bytes, 0, bytes.Length);
fs.Close();
Response.ContentType = "application/octet-stream";//通知浏览器下载文件而不是打开
Response.AddHeader("Content-Disposition", "attachment; filename=" + HttpUtility.UrlEncode("文件名.doc", System.Text.Encoding.UTF8));
Response.BinaryWrite(bytes);
Response.Flush();
Response.End();
如System.Diagnostics.Process Process1 = new System.Diagnostics.Process();
Process1.StartInfo.FileName = "Winrar.exe";
Process1.StartInfo.CreateNoWindow = true;
或输出二进制流数据