Esempio n. 1
0
        //二、WriteFile实现下载
        protected void Button2_Click(object sender, EventArgs e)
        {
            /*         using System.IO;        */
            string fileName = "asd.txt";
            //客户端保存的文件名
            string filePath = Server.MapPath("DownLoad/aaa.txt");
            //路径
            FileInfo fileInfo = new FileInfo(filePath);

            Response.Clear();
            Response.ClearContent();
            Response.ClearHeaders();
            Response.AddHeader("Content-Disposition", "attachment;filename=" + fileName);
            Response.AddHeader("Content-Length", fileInfo.Length.ToString());
            Response.AddHeader("Content-Transfer-Encoding", "binary");
            Response.ContentType     = "application/octet-stream";
            Response.ContentEncoding = System.Text.Encoding.GetEncoding("gb2312");
            Response.WriteFile(fileInfo.FullName);
            Response.Flush();
            Response.End();
        }