dotnetzip

DotNetZip - Calculate final zip size before calling Save(stream) in C#

你说的曾经没有我的故事 提交于 2019-11-27 06:14:00
问题 When using DotNetZip, is it possible to get what the final zip file size will be before calling Save(stream)? I have a application(Window Service) where package Stream size is more than 100MB then package will saved and upcoming files add into new package. I got same question for web application but not understand the answer. Is there any way into DotnetZip to find the size of zip stream before save on I/O system? 回答1: I got the solution. Here is code.Now I will create the package which size

Extract a ZIP file programmatically by DotNetZip library?

旧时模样 提交于 2019-11-27 05:42:58
问题 I have a function that get a ZIP file and extract it to a directory (I use DotNetZip library.) public void ExtractFileToDirectory(string zipFileName, string outputDirectory) { ZipFile zip = ZipFile.Read(zipFileName); Directory.CreateDirectory(outputDirectory); zip.ExtractAll(outputDirectory,ExtractExistingFileAction.OverwriteSilently); } My ZIP file contains multiple files and directories. But I want to extract only some of these files, not all of them. How can I make this work? 回答1: You need

Creating Zip file from stream and downloading it

自闭症网瘾萝莉.ら 提交于 2019-11-27 04:21:42
问题 I have a DataTable that i want to convert it to xml and then zip it, using DotNetZip. finally user can download it via Asp.Net webpage. My code in below dt.TableName = "Declaration"; MemoryStream stream = new MemoryStream(); dt.WriteXml(stream); ZipFile zipFile = new ZipFile(); zipFile.AddEntry("Report.xml", "", stream); Response.ClearContent(); Response.ClearHeaders(); Response.AppendHeader("content-disposition", "attachment; filename=Report.zip"); zipFile.Save(Response.OutputStream); /

DotNetZip add files without creating folders

给你一囗甜甜゛ 提交于 2019-11-26 16:33:45
问题 using (ZipFile zip = new ZipFile()) { foreach(string file in Directory.GetFiles(folder)) { zip.AddFile(file, Path.GetFileName(file)); } zip.Save("test.zip")); } Each time I add a file, it's creating a new subfolder for it. So I want to end up with: test.zip - myDoc.doc - myPdf.pdf but I'm ending up with: test.zip - myDoc.doc - myDoc.doc - myPdf.pdf - myPdf.pdf 回答1: How about just: zip.AddFile(file,""); or zip.AddFile(file,@"\"); 回答2: Becouse aproved answer was 4 years ago now a days is

Downloading of zip file through ASP.NET MVC using DotNetZip

情到浓时终转凉″ 提交于 2019-11-26 16:22:37
问题 I have created a text file in a folder and zipped that folder and saved @same location for test purpose. I wanted to download that zip file directly on user machine after it is created. I am using dotnetzip library and have done following: Response.Clear(); Response.ContentType = "application/zip"; Response.AddHeader("content-disposition", "filename=" + "sample.zip"); using (ZipFile zip = new ZipFile()) { zip.AddDirectory(Server.MapPath("~/Directories/hello")); zip.Save(Server.MapPath("~