码迷,mamicode.com
首页 > Web开发 > 详细

asp.net文件下载

时间:2015-05-29 17:49:39      阅读:142      评论:0      收藏:0      [点我收藏+]

标签:

  xmlDoc.Save(xmlSavePath);
                FileStream fileStream = new FileStream(xmlSavePath, FileMode.Open);
                long fileSize = fileStream.Length;
                byte[] fileBuffer = new byte[fileSize];
                fileStream.Read(fileBuffer, 0, (int)fileSize);
                //如果不写fileStream.Close()语句,用户在下载过程中选择取消,将不能再次下载
                fileStream.Close();

                Context.Response.ContentType = "application/octet-stream";
                Context.Response.AppendHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(DateTime.Now.ToString("yyyyMMddhhmmss") + ".xml", Encoding.UTF8));
                Context.Response.AddHeader("Content-Length", fileSize.ToString());

                Context.Response.BinaryWrite(fileBuffer);
                Context.Response.End();
                Context.Response.Close();

  

asp.net文件下载

标签:

原文地址:http://www.cnblogs.com/colin2011/p/4538965.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!