VS2005里面如何实现文件的下载功能 在线急等````` 如果文件存在服务器上,直接在页面<a href="相对路径/文件名.rar">asp教程下载</a>存在数据库里的文件需要打开数据源通过参数来传递 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 我也是最近才找的。给你代码吧.public void download() { string path = Server.MapPath(@"需要下载文件的地址(服务器端的)"); //下载文件的名称 string filename = "c.doc"; System.IO.FileInfo toDownload = new System.IO.FileInfo(path); if (toDownload.Exists == true) { const long ChunkSize = 10000; byte[] buffer = new byte[ChunkSize]; Response.Clear(); System.IO.FileStream iStream = System.IO.File.OpenRead(path); long dataLengthToRead = iStream.Length; Response.ContentType = "application/octet-stream"; Response.AddHeader("Content-Disposition", "attachment; filename=new_" + HttpUtility.UrlEncode(toDownload.Name)); while (dataLengthToRead > 0 && Response.IsClientConnected) { int lengthRead = iStream.Read(buffer, 0, Convert.ToInt32(ChunkSize)); Response.OutputStream.Write(buffer, 0, lengthRead); Response.Flush(); dataLengthToRead = dataLengthToRead - lengthRead; Response.WriteFile(filename); } Response.Close(); } } 唉,还是感觉有点难啊!~~~~(>_<)~~~~ Response.Redirect("URL")<a herf = "URL"></a>Response.Write("<script>window.open('URL')</script>")不过以上都是系统自带的,用的是单线程如果使用频率少,切文件相对较小,可以用以上方法.如果使用频率较多,就使用多线程断点下载,就去网上找找吧,现成的一大堆,只需调用就行了 用到了字节流,有点深,依我看还是用<a href="相对路径/文件名.rar">asp教程下载 </a>简单,数据库方面连上地址(最好是物理地址,不容易出错)就OK了! VisualC#中如何更新数据表的数据 新手问登录界面用户验证为什么都这样做 |ZYCWPF| 自动百度回贴已经可以,但网页会提示Active控件,帮看看写法是否科学?如何更好的进行实现?谢谢 有示例源码 这是最简单的c#程序吗?最少代码行?还能再少行吗? ActiveX控件如何传值 求助datagridview File.delete不支持通配符? 一个关于.net框架的问题,正解另开帖给分200。 求reflector反编译工具 MVVM下的WPF自定义控件 c# GDI+多个柱状和多条曲线缩放、切换 [源码1] 请问C#控制台应用程序里怎么调用自己写的函数?
{
string path = Server.MapPath(@"需要下载文件的地址(服务器端的)");
//下载文件的名称
string filename = "c.doc";
System.IO.FileInfo toDownload = new System.IO.FileInfo(path); if (toDownload.Exists == true)
{
const long ChunkSize = 10000;
byte[] buffer = new byte[ChunkSize]; Response.Clear();
System.IO.FileStream iStream = System.IO.File.OpenRead(path);
long dataLengthToRead = iStream.Length;
Response.ContentType = "application/octet-stream";
Response.AddHeader("Content-Disposition", "attachment; filename=new_" + HttpUtility.UrlEncode(toDownload.Name));
while (dataLengthToRead > 0 && Response.IsClientConnected)
{
int lengthRead = iStream.Read(buffer, 0, Convert.ToInt32(ChunkSize));
Response.OutputStream.Write(buffer, 0, lengthRead);
Response.Flush();
dataLengthToRead = dataLengthToRead - lengthRead;
Response.WriteFile(filename);
}
Response.Close();
}
}
<a herf = "URL"></a>
Response.Write("<script>window.open('URL')</script>")
不过以上都是系统自带的,用的是单线程
如果使用频率少,切文件相对较小,可以用以上方法.如果使用频率较多,
就使用多线程断点下载,就去网上找找吧,现成的一大堆,只需调用就行了