Code
public class Download : IHttpHandler
{
public void ProcessRequest(HttpContext context)
{
//得到请求的路径
string path = context.Server.UrlDecode(context.Request.QueryString["file"]);
System.IO.FileStream fs = System.IO.File.Open(path, System.IO.FileMode.Open);
context.Response.Clear();
string p = path.Substring(path.LastIndexOf("/") + 1);
string strTemp = System.Web.HttpUtility.UrlEncode(p, System.Text.Encoding.UTF8);//解决文件名乱码
context.Response.AddHeader("content-disposition", "attachment;filename=" + strTemp);
context.Response.ContentType = "application/octet-stream";
int b = fs.ReadByte();
while (b != -1)
{
context.Response.BinaryWrite(new byte[] { (byte)b });
b = fs.ReadByte();
}
fs.Close();
HttpContext.Current.ApplicationInstance.CompleteRequest();
}
public bool IsReusable
{
get
{
return false;
}
}
}
我有个下载功能,当点击下载的时候,我是用迅雷下载的 可是它的进度一直为0,好像不可以用迅雷!请问是什么原因?
又或者谁能给个下载功能的例子或代码?谢谢……