首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > asp.net >

点击下载效能

2014-01-14 
点击下载功能点击,转到一般处理程序,在一般处理程序中将数据库中二进制流转换后,实现下载public void Proc

点击下载功能
点击,转到一般处理程序,在一般处理程序中将数据库中二进制流转换后,实现下载
public void ProcessRequest(HttpContext context)
        {
            Guid FileID = Guid.Parse(context.Request.Params["fileid"].ToString());

            XML_SYS_FILEEntity file = new XML_SYS_FILEEntity() { XFL_ID = FileID };
            if (file.RemotingInitEntity<SYSTEMLink>())
            {
                string FileName = System.Web.HttpUtility.UrlEncode(System.Text.Encoding.UTF8.GetBytes(file.XFL_FILE_NAMEDisplayValue + file.XFL_FILE_EXTEND_NAMEDisplayValue));
                string leng = file.XFL_FILE_LENGTHDisplayValue;

                context.Response.Clear();
                context.Response.ContentType = "application/octet-stream";
                context.Response.AddHeader("Content-Disposition", "attachement;filename=" + file.XFL_FILE_NAMEDisplayValue);
                context.Response.AddHeader("Content-Length", leng.ToString());
                context.Response.BinaryWrite(file.XFL_FILE_BYTES);
                context.Response.End();
            }
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
但是点击后便直接打开了文件
[解决办法]
 Response.Clear();
            Response.ClearHeaders();
            Response.Buffer = true;
            Response.AddHeader("Content-Length", fi.Length.ToString());
            Response.ContentType = "application/application/octet-stream";
            Response.AddHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(fi.Name));
            Response.WriteFile(fi.FullName);
            Response.End();
            Response.Flush();
            Response.Clear();
[解决办法]

引用:
 Response.Clear();
            Response.ClearHeaders();
            Response.Buffer = true;
            Response.AddHeader("Content-Length", fi.Length.ToString());
            Response.ContentType = "application/application/octet-stream";
            Response.AddHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(fi.Name));
            Response.WriteFile(fi.FullName);
            Response.End();
            Response.Flush();
            Response.Clear();


+1
Response.AddHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(fi.Name));
是关键

热点排行