在线生成压缩文件并下载

            using (MemoryStream ms = new MemoryStream())
            {
                using (ZipArchive archive = new ZipArchive(ms, ZipArchiveMode.Update,true))
                {
                    string filename = "过程材料.doc";
                    ZipArchiveEntry readMeEntry = archive.CreateEntry(filename);
                    using (System.IO.Stream stream = readMeEntry.Open())
                    {
                        doc.Save(stream, SaveFormat.Doc);
                    }
                }

                ms.Flush();
                ms.Position = 0;

                //设置编码和附件格式
                Response.ContentType = "application/x-zip-compressed";
                Response.ContentEncoding = Encoding.UTF8;
                Response.Charset = "";
                Response.AppendHeader("Content-Disposition",
                    "attachment;filename=" + HttpUtility.UrlEncode(strFileName, Encoding.UTF8));
                Response.Clear();
                Response.BufferOutput = true;

                ms.CopyTo(Response.OutputStream);
                //Response.BinaryWrite(ms.GetBuffer());
                Response.End();
            }

 

posted @ 2015-11-22 21:01  shiningrise  阅读(674)  评论(0编辑  收藏  举报
// 侧边栏目录 // https://blog-static.cnblogs.com/files/douzujun/marvin.nav.my1502.css