DotNetZip 压缩下载

var fs = Response.OutputStream;
            using (ZipFile zip = new ZipFile(System.Text.Encoding.UTF8)) //编码是解决中文问题
            {
                foreach (var order in orders)
                {
                    foreach (var orderItem in order.OrderItems)
                    {
                        var filePath = order.Id.ToString("000000");
                        var orderPro = orderItem.Product;
                        if (orderPro != null)
                        {
                            filePath += "/" + orderPro.Name + "_" + string.Join("_", orderPro.ProductDiyAttributes.Select(x=>x.Value))+"("+orderItem.Quantity+")";
                            var printImages =
                                orderPro.ProductPictures.Where(pp=>!string.IsNullOrEmpty(pp.PrintImageUrl)).Select(x => _webHelper.MapPath(x.PrintImageUrl))
                                    .ToList();
                            zip.AddFiles(printImages,filePath);
                        }
                    }
                }
                zip.Save(fs);//保存到输出流
            }
            string fileName = "printimage.zip";
            Response.ContentType = "application/octet-stream";
            Response.AddHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(fileName, System.Text.Encoding.UTF8));
            //Response.BinaryWrite(bytes);
            Response.Flush();
            Response.End();
原文地址:https://www.cnblogs.com/ideacore/p/6289586.html