ITPub博客

首页 > > > 这段下载代码有什么问题吗

这段下载代码有什么问题吗

作者:llittle 时间:2019-10-16 10:43:55 0 删除 编辑
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/ ,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论

注册时间:2019-04-12

  • 博文量
    448
  • 访问量
    4398