做外贸免费的网站有哪些,企业网页制作与网站设计,wordpress社区聊天室,网站换主题MVC实现实现文件流打包成压缩包1、使用压缩类库SharpZipLib SharpZipLib 是一款比较经典实用C#压缩类库SharpZipLib 库特点#xff1a;功能丰富、稳定 #xff0c;支持主流 zip、Gzip Tar BZip2 格式2、项目中引用SharpZipLib的官方地址是#xff1a;http://icsharpcode.git… MVC实现实现文件流打包成压缩包1、使用压缩类库SharpZipLib SharpZipLib 是一款比较经典实用C#压缩类库SharpZipLib 库特点功能丰富、稳定 支持主流 zip、Gzip Tar BZip2 格式2、项目中引用SharpZipLib的官方地址是http://icsharpcode.github.io/SharpZipLib/实际使用可以通过NuGet获取在NuGet的地址是http://www.nuget.org/packages/SharpZipLib/在Visual Studio中可以通过NuGet程序包管理控制台输入命令PM Install-Package SharpZipLib或者用NuGet管理界面搜索并安装。需要引用命名空间 using ICSharpCode.SharpZipLib.Checksums; using ICSharpCode.SharpZipLib.Zip; using System.IO;3、MVC代码示例 直接从文件流输出zip//控制器写法public FileResult PrintData(){ byte[] bytePDF 需要打包的文件流; byte[] result null; using (MemoryStream ms new MemoryStream()) { using (ZipOutputStream zipStream new ZipOutputStream(ms)) { zipStream.Password 123456;//设置压缩包密码 ZipEntry entry new ZipEntry(文件名); entry.DateTime DateTime.Now;//创建时间 zipStream.PutNextEntry(entry); zipStream.Write(bytePDF, 0, bytePDF.Length); zipStream.CloseEntry(); zipStream.IsStreamOwner false; zipStream.Finish(); zipStream.Close(); ms.Position 0; //压缩后的数据被保存到了byte[]数组中。 result ms.ToArray(); } } return File(result, application/zip, 文件名.zip); }