日斋
日新月异

 /// <summary>
        /// 下载附件方法
        /// </summary>
        private void DownLoad()
        {
            Response.Expires = -1;
            string filename = Guid.NewGuid().ToString() + ".txt";
            filename = Server.MapPath(filename);
            StreamWriter write = new StreamWriter(filename, true, System.Text.Encoding.UTF8);
            write.WriteLine(this.txtException.Text);
            write.Flush();
            write.Close();

            Response.Clear();
            Response.ClearHeaders();
            //Response.Buffer = false;
            System.IO.FileInfo fi = new FileInfo(filename);
            Response.ContentType = "application/octet-stream";
            Response.AppendHeader("Content-Disposition", "attachment;filename= " + HttpUtility.UrlEncode(fi.FullName, System.Text.Encoding.UTF8));
            Response.AppendHeader("Content-Length ", fi.Length.ToString());
            Response.WriteFile(fi.FullName);
            Response.Flush();
            System.IO.File.Delete(filename);
            Response.End();
        }

posted on 2010-03-10 10:34  李承隆  阅读(118)  评论(0编辑  收藏  举报