Asp.Net中文件下载

来源:互联网 发布:php自动加载类参数 编辑:程序博客网 时间:2024/05/09 03:53

        /// <param name="strDownloadFile">绝对路径</param>
        public void HTTP_DownloadFile(string strDownloadFile)
        {
            // strDownloadFile 是绝对路径,可以通过 Server.MapPath 提供
            string strShortFileName = Path.GetFileNameWithoutExtension(strDownloadFile);
            string strClientFileName = strShortFileName.Substring(0,strShortFileName.Length - 18)
                + Path.GetExtension(strDownloadFile);
            strClientFileName = Server.UrlEncode(strClientFileName);
   
            pge_client.Response.Clear();
            pge_client.Response.ContentType = "application/octet-stream";
            pge_client.Response.AddHeader("Content-Disposition", "attachment;filename=" + strClientFileName);
            pge_client.Response.Flush();
            pge_client.Response.WriteFile(strDownloadFile, false); // 下载文件
            pge_client.Response.End(); // 此句不能缺少,否则会把本页的HTML源码写在文件里
        }

 

原创粉丝点击