<%@ WebHandler Language="C#" Class="Downs" %> using System; using System.Web; using System.IO; using System.Linq; public class Downs : IHttpHandler { public void ProcessRequest (HttpContext context) { context.Response.ContentType = "text/plain"; DataClassesDataContext dl = new DataClassesDataContext(); string urls = context.Request["url"]; if (urls != "") { try { if (urls.IndexOf('/') == 0) { FileDownload(context.Server.MapPath("~" + urls)); } else { FileDownload(context.Server.MapPath("~/" + urls)); } } catch { } } else { context.Response.Write("对不起,暂无上传要下载的信息!!!"); } } public void FileDownload(string strFullName)//下载文件绝对路径 { FileInfo DownloadFile = new FileInfo(strFullName); HttpContext.Current.Response.Clear(); HttpContext.Current.Response.ClearHeaders(); HttpContext.Current.Response.Buffer = false; HttpContext.Current.Response.ContentType = "application/octet-stream"; HttpContext.Current.Response.AppendHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(DownloadFile.Name, System.Text.Encoding.UTF8)); HttpContext.Current.Response.AppendHeader("Content-Length", DownloadFile.Length.ToString()); HttpContext.Current.Response.WriteFile(DownloadFile.FullName);//DownloadFile.FullName保存文件名 HttpContext.Current.Response.Flush(); HttpContext.Current.Response.End(); } public bool IsReusable { get { return false; } } }