.net怎么实现多文件下载 我要选择checkbox实现多文件下载。不知道怎么实现。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 windows.open("file1");windows.open("file2");......windows.open("filen"); 也可以调用迅雷的 方法 set ThunderAgent = CreateObject("ThunderAgent.Agent.1")call ThunderAgent.AddTask4()call ThunderAgent.CommitTasks2(1) 楼上的,我要选择多个文件,一次性打包下载下来。网上有什么WebClient方法不知道行不行。我点击单个文件可以下载,用的代码是这样的。FileStream myFile = new FileStream(_fullPath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite); BinaryReader br = new BinaryReader(myFile); try { _Response.AddHeader("Accept-Ranges", "bytes"); _Response.Buffer = false; long fileLength = myFile.Length; long startBytes = 0; int pack = 10240; //10K bytes //int sleep = 200; //每秒5次 即5*10K bytes每秒 int sleep = (int)Math.Floor((decimal)(1000 * pack / _speed)) + 1; if (_Request.Headers["Range"] != null) { _Response.StatusCode = 206; string[] range = _Request.Headers["Range"].Split(new char[] { '=', '-' }); startBytes = Convert.ToInt64(range[1]); } _Response.AddHeader("Content-Length", (fileLength - startBytes).ToString()); if (startBytes != 0) { _Response.AddHeader("Content-Range", string.Format(" bytes {0}-{1}/{2}", startBytes, fileLength - 1, fileLength)); } _Response.AddHeader("Connection", "Keep-Alive"); _Response.ContentType = "application/octet-stream"; _Response.AddHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(_fileName, System.Text.Encoding.UTF8)); br.BaseStream.Seek(startBytes, SeekOrigin.Begin); int maxCount = (int)Math.Floor((decimal)((fileLength - startBytes) / pack)) + 1; for (int i = 0; i < maxCount; i++) { if (_Response.IsClientConnected) { _Response.BinaryWrite(br.ReadBytes(pack)); Thread.Sleep(sleep); } else { i = maxCount; } } 一次性打包下载是要先在服务器端打包的, 一般使用winrar然后重定向 可以使用一个叫ICSharpCode.SharpZipLib.dll的组件。思路就是:1.将多个要下载的文件添加到一个压缩包里,2.将生成的压缩包下载到客户端。 我的来推荐一个在线课程试听http://www.cdlanhai.com/zxst/ 搞定了,我用ICSharpCode.SharpZipLib.dll,方法大家网络搜下就有。 在frame.html页面点击超链接后退出到登陆页面,清空session Repeater Checkbox 全选 求修改当鼠标移到倒数第3个图片时,出现的层向里面显现 sql数据备份问题 js控制隐藏和展开遇到的的问题(换用ajaxToolkitCollapsiblePanelExtender控件也这样的问题) 表单提交到不同页面 C#.net新手提问 Web开发中,Com对象被应用的方式有几种?多多探讨 百分求助交流学习 如何为动态加载的树形控件的节点关联显示一个checkbox? 关于vs2008的汉化 TreeView 动态加载树目录,急急急!!!
windows.open("file2");
......
windows.open("filen");
set ThunderAgent = CreateObject("ThunderAgent.Agent.1")call ThunderAgent.AddTask4()call ThunderAgent.CommitTasks2(1)
网上有什么WebClient方法不知道行不行。我点击单个文件可以下载,用的代码是这样的。
FileStream myFile = new FileStream(_fullPath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
BinaryReader br = new BinaryReader(myFile);
try
{
_Response.AddHeader("Accept-Ranges", "bytes");
_Response.Buffer = false;
long fileLength = myFile.Length;
long startBytes = 0; int pack = 10240; //10K bytes
//int sleep = 200; //每秒5次 即5*10K bytes每秒
int sleep = (int)Math.Floor((decimal)(1000 * pack / _speed)) + 1;
if (_Request.Headers["Range"] != null)
{
_Response.StatusCode = 206;
string[] range = _Request.Headers["Range"].Split(new char[] { '=', '-' });
startBytes = Convert.ToInt64(range[1]);
}
_Response.AddHeader("Content-Length", (fileLength - startBytes).ToString());
if (startBytes != 0)
{
_Response.AddHeader("Content-Range", string.Format(" bytes {0}-{1}/{2}", startBytes, fileLength - 1, fileLength));
}
_Response.AddHeader("Connection", "Keep-Alive");
_Response.ContentType = "application/octet-stream";
_Response.AddHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(_fileName, System.Text.Encoding.UTF8)); br.BaseStream.Seek(startBytes, SeekOrigin.Begin);
int maxCount = (int)Math.Floor((decimal)((fileLength - startBytes) / pack)) + 1; for (int i = 0; i < maxCount; i++)
{
if (_Response.IsClientConnected)
{
_Response.BinaryWrite(br.ReadBytes(pack));
Thread.Sleep(sleep);
}
else
{
i = maxCount;
}
}
然后重定向
1.将多个要下载的文件添加到一个压缩包里,
2.将生成的压缩包下载到客户端。