Code
<%@ WebHandler Language="C#" Class="Download" %>
using System;
using System.Web;
public class Download : IHttpHandler
{
public void ProcessRequest(HttpContext context)
{
string fileserverpath = context.Server.UrlDecode(context.Request.QueryString["file"]);
System.IO.FileInfo fi = new System.IO.FileInfo(fileserverpath);
fi.Attributes = System.IO.FileAttributes.Normal;
System.IO.FileStream filestream = new System.IO.FileStream(fileserverpath, System.IO.FileMode.Open);
long filesize = filestream.Length;
int i = Convert.ToInt32(filesize);
string p = fileserverpath.Substring(fileserverpath.LastIndexOf("/") + 1);
string strTemp = System.Web.HttpUtility.UrlEncode(p, System.Text.Encoding.UTF8);//解决文件名乱码
context.Response.ContentType = "application/octet-stream";
context.Response.AddHeader("Content-Disposition", "attachment; filename=" +strTemp);
context.Response.AddHeader("Content-Length", filesize.ToString());
byte[] fileBuffer = new byte[i];
filestream.Read(fileBuffer, 0, i);
filestream.Close();
context.Response.BinaryWrite(fileBuffer);
}
public bool IsReusable
{
get
{
return false;
}
}
}
这段代码在本地可以下载,可是到了服务器上不行!进度老是为0,请问是什么原因?