??下载的问题 各位老大: 小弟刚刚学会做下载,可以下dd了,但遇到部分可执行的文件如.mp3.asp.rm的各位老大我要怎么做才能让他左键点击后可以下载呢 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 to:dcren118(地狱黑客) 右键--》目标另寸客户不一定用这个啊 程序的大概如下:// aspx 页面<a href=DownloadFile.aspx?fileID=xxxxxx>点击下载</a>// DownloadFile.aspxvoid Page_Load(...){ ... // 向 Http 写回文件流 response.ContentType = "application/x-download"; response.AppendHeader("Content-Disposition", "attachment; FileName=" + HttpUtility.UrlEncode(fileName)); response.BufferOutput = false; ... Stream fs = new FileStream("xxxx", ....); while (...) { fs.Read(buffer, 0, 4096); Response.OutputStream.Write(buffer, 0, 4096); } .... } 也就是你要自己控制文件的发送过程了,而不是简单地把连接重定向到物理文件链接上。发送文件时,首先要设置ContentType="application/x-download";这一点很重要;然后要添加Content-Disposition头,也就是response.AppendHeader("Content-Disposition", "attachment; FileName=" + HttpUtility.UrlEncode(fileName));这个也很重要,时关键的两步。最后就是循环读取文件内容并以二进制的方式写到 Response的 OutputStream 里了。 怎么给div做链接 字符串的截取问题 代码出错!!!! .Net适合开发大型门户么?为什么绝大多数门户 没有选择它? 求教高手~~帮小弟下 有遇到过这种情况的吗? 安装好VS2003后,想建立ASP.NET项目,发现问题,请高手帮忙!谢谢! “在关键字 'user' 附近有语法错误”郁闷的事情 现在学软件开发的是不是都得去培训啊? 希冀大山的回音!!!!!!!!!! asp.net发邮件出现错误,请高手看看那里错了(代码) 总感觉ASP。NET做出来的程序都还是有点慢。。
客户不一定用这个啊
<a href=DownloadFile.aspx?fileID=xxxxxx>点击下载</a>
// DownloadFile.aspxvoid Page_Load(...)
{
...
// 向 Http 写回文件流
response.ContentType = "application/x-download";
response.AppendHeader("Content-Disposition", "attachment; FileName=" + HttpUtility.UrlEncode(fileName));
response.BufferOutput = false;
...
Stream fs = new FileStream("xxxx", ....);
while (...)
{
fs.Read(buffer, 0, 4096);
Response.OutputStream.Write(buffer, 0, 4096);
} ....
}
然后要添加Content-Disposition头,也就是response.AppendHeader("Content-Disposition", "attachment; FileName=" + HttpUtility.UrlEncode(fileName));这个也很重要,时关键的两步。
最后就是循环读取文件内容并以二进制的方式写到 Response的 OutputStream 里了。