嗨波

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理
  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();

  

posted on 2015-05-29 16:59  嗨波  阅读(187)  评论(0编辑  收藏  举报