首页 > > > 这段下载代码有什么问题吗
try
{
string filepath = context.Server.MapPath(context.Request.QueryString["filedir"].ToString() + "/" + context.Request.QueryString[0].Substring(0, 4).ToString() + "/" + context.Request.QueryString[0].ToString());
string filename = context.Request.QueryString[1].ToString();
FileInfo info = new FileInfo(filepath);
long fileSize = info.Length;
context.Response.Clear();
context.Response.ContentType = "application/x-zip-compressed";
context.Response.AddHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(filename, System.Text.Encoding.UTF8));
//不指明Content-Length用Flush的话不会显示下载进度
context.Response.AddHeader("Content-Length", fileSize.ToString());
context.Response.TransmitFile(filepath, 0, fileSize);
context.Response.Flush();
context.Response.Close();
}
catch
{ }来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/813/viewspace-3168949/ ,如需转载,请注明出处,否则将追究法律责任。