文件下载的功能怎么做,怎样支持用迅雷下载的?

CodeShow 2008-10-13 10:47:54
我的代码如下,但只能用"另存为"下载:

string abcName = "abc.rar"; //文件名
string dName = "~/upload/" + abcName; //路径
string filepath = Server.MapPath(dName);
string filename = Path.GetFileName(filepath);

Response.Clear();
Response.ContentType = "application/octet-stream";
Response.AddHeader("Content-Disposition", "attachment; filename=" + HttpUtility.UrlEncode(abcName, System.Text.Encoding.UTF8));
Response.WriteFile(filepath);


请问怎么写才能支持迅雷?
...全文
343 12 打赏 收藏 转发到动态 举报
写回复
用AI写文章
12 条回复
切换为时间正序
请发表友善的回复…
发表回复
Q321asdfg 2010-08-11
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 q704174307 的回复:]
楼上的,厉害,我觉得好像不用设置吧,浏览器默认使用迅雷下载就能了,我是这样过来的
[/Quote]
你也太绝了吧 做些网站是给别人用 而不是自己用! 难道对所有的用户都说把“浏览器默认使用迅雷下载”吗!
CodeShow 2008-10-13
  • 打赏
  • 举报
回复
你这个类怎么用的
public static bool DownLoadFile(HttpRequest MyRequest, HttpResponse MyResponse, string MyFileName, string MyFullPath, long MySpeed)

我对Asp.Net还不够熟悉,请问一下MyRequest,MyResponse这两个参数怎么传值的?
cong1212 2008-10-13
  • 打赏
  • 举报
回复
学习一下
winner2050 2008-10-13
  • 打赏
  • 举报
回复
一行代码就可以了。

HttpContext.Current.Response.Redirect( 软件的路径 );
「已注销」 2008-10-13
  • 打赏
  • 举报
回复
mark
三碗猪脚 2008-10-13
  • 打赏
  • 举报
回复
关注中....
lee576 2008-10-13
  • 打赏
  • 举报
回复
http://d.download.csdn.net/source/407990

调用迅雷多文件下载(C#)

上面的代码没看过,请楼主自动研究
pcitlju 2008-10-13
  • 打赏
  • 举报
回复
学习。。。
q704174307 2008-10-13
  • 打赏
  • 举报
回复
楼上的,厉害,我觉得好像不用设置吧,浏览器默认使用迅雷下载就能了,我是这样过来的
lee576 2008-10-13
  • 打赏
  • 举报
回复
关注一下,怎么支持迅雷还真没做过
yangpeiyu 2008-10-13
  • 打赏
  • 举报
回复

///<summary>
/// 输出硬盘文件,提供下载 支持大文件、续传、速度限制、资源占用小
/// </summary>
/// <param name="MyRequest">Page.Request对象</param>
/// <param name="MyResponse">Page.Response对象</param>
/// <param name="MyFileName">下载文件名</param>
/// <param name="MyFullPath">带文件名下载路径</param>
/// <param name="MySpeed">每秒允许下载的字节数</param>
/// <returns>True Or False</returns>
public static bool DownLoadFile(HttpRequest MyRequest, HttpResponse MyResponse, string MyFileName, string MyFullPath, long MySpeed)
{
try
{
FileStream myFile = new FileStream(MyFullPath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
BinaryReader br = new BinaryReader(myFile);

try
{
MyResponse.AddHeader("Accept-Ranges", "bytes");
MyResponse.Buffer = false;

long fileLength = myFile.Length;
long startBytes = 0;
int pack = 10240; //10K bytes
int sleep = (int)Math.Floor(1000.0 * pack / MySpeed) + 1;

if (MyRequest.Headers["Range"] != null)
{
MyResponse.StatusCode = 206;
string[] range = MyRequest.Headers["Range"].Split(new char[] { '=', '-' });
startBytes = Convert.ToInt64(range[1]);
}

MyResponse.AddHeader("Content-Length", (fileLength - startBytes).ToString());

if ((startBytes != 0))
{
MyResponse.AddHeader("Content-Range", string.Format(" bytes {0}-{1}/{2}", startBytes, fileLength - 1, fileLength));
}

MyResponse.AddHeader("Connection", "Keep-Alive");
MyResponse.ContentType = "application/octet-stream";
MyResponse.AddHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(MyFileName, System.Text.Encoding.UTF8));
br.BaseStream.Seek(startBytes, SeekOrigin.Begin);

int maxCount = (int)Math.Floor(1.0 * (fileLength - startBytes) / pack) + 1;

for (int i = 0; i <= maxCount; i++)
{
if ((MyResponse.IsClientConnected))
{
MyResponse.BinaryWrite(br.ReadBytes(pack));
System.Threading.Thread.Sleep(sleep);
}
else
{
i = maxCount;
}
}
}
catch
{
return false;
}
finally
{
br.Close(); myFile.Close();
}
}
catch
{
return false;
}
return true;
}
maquexuefei 2008-10-13
  • 打赏
  • 举报
回复
直接用超级链接,点击就能用迅雷下载,还能另存为,最多中转个页面,做些判断,下个文件,不用那么复杂吧?我做错了吗?

62,047

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧