62,074
社区成员
发帖
与我相关
我的任务
分享
public void ProcessRequest(HttpContext context)
{
string url = context.Request.QueryString["url"];
try
{
url = HttpContext.Current.Server.UrlEncode(url.Trim());
downloadfile(url);
}
catch (ArgumentException ex)
{
return;
}
}
public void downloadfile(string s_fileName)
{
HttpContext.Current.Response.ContentType = "application/ms-download";
s_fileName = HttpContext.Current.Server.UrlDecode(s_fileName);
string s_path = HttpContext.Current.Server.MapPath("~/")+@"download\excel\" + s_fileName;
System.IO.FileInfo file = new System.IO.FileInfo(s_path);
HttpContext.Current.Response.Clear();
HttpContext.Current.Response.AddHeader("Content-Type", "application/octet-stream");
HttpContext.Current.Response.Charset = "GB2312";
HttpContext.Current.Response.AddHeader("Content-Disposition", "attachment;filename=" + System.Web.HttpUtility.UrlEncode(file.Name, System.Text.Encoding.UTF8));
HttpContext.Current.Response.AddHeader("Content-Length", file.Length.ToString());
HttpContext.Current.Response.WriteFile(file.FullName);
HttpContext.Current.Response.Flush();
HttpContext.Current.Response.Clear();
HttpContext.Current.Response.End();
}
System.IO.FileInfo info =new System.IO.FileInfo(Server.MapPath(@"../FileManage/upload/" +s_fileName));
Response.Clear();
Response.ClearContent();
Response.ClearHeaders();
string urlName = HttpUtility.UrlEncode(s_fileName, System.Text.Encoding.UTF8);
Response.AddHeader("Content-Disposition", "attachment;filename=" + urlName);
Response.AddHeader("Content-Length", info.Length.ToString());
Response.AddHeader("Content-Transfer-Encoding", "binary");
Response.ContentType = "application/octet-stream";
Response.ContentEncoding = System.Text.Encoding.GetEncoding("gb2312");
Response.WriteFile(info.FullName);
Response.Flush();
Response.End();