博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
DotNetZip 压缩下载
阅读量:5151 次
发布时间:2019-06-13

本文共 1451 字,大约阅读时间需要 4 分钟。

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

你可能感兴趣的文章