dotnetzip

Using a MemoryStream with FileStreamResult possible?

青春壹個敷衍的年華 提交于 2019-11-29 09:08:39
I'm using DotNetZip to create a zip file and pass it to a FileResult. On debug, I can verify that the MemoryStream contains a file, but when I run it through FileStreamResult, it returns 0bytes: public FileResult GetZipFiles(int documentId) { var file = fileRepository.Get(documentId); var zip = new ZipFile(); var stream = new MemoryStream(); var filePath = Path.Combine(UploadsFolder, Path.GetFileName(file.Id)); zip.AddFile(filePath); zip.Save(stream); var result = new FileStreamResult(stream, "application/zip") { FileDownloadName = "hey.zip" }; return result; } Again, I can verify that stream

How to zip only files and not the full path hierarchy with DotNetZip in powershell?

泄露秘密 提交于 2019-11-29 03:19:38
I'm trying to zip up log using DotNetZip and powershell. The files are in C:\user\temp\logs When I loop through the logs in the directory and add them to the zip file, I end up with the folder hierarchy and the log files when I only want the log files. So the zip ends up containing: -user └temp └logs └log1.log log2.log log3.log When I want the zip file to contain is: log1.log log2.log log3.log Here is the script I'm running to test with: [System.Reflection.Assembly]::LoadFrom("c:\\\User\\bin\\Ionic.Zip.dll"); $zipfile = new-object Ionic.Zip.ZipFile("C:\user\temp\logs\TestZIP.zip"); $directory

Ionic.Zip library unable to extract .rar file C#

强颜欢笑 提交于 2019-11-28 10:08:38
问题 I am trying to extract .rar file using .net zip library (Ionic.Zip.dll). I got error " cannot read that as a zipfile " while executing following code; using (ZipFile zip1 = ZipFile.Read("E:\\APPS\\package.rar")){ } I know the error is self explanatory but documentation of Ionic.Zip says that it can be used to extract .rar files. Any ideas? 回答1: Well, I not found anywhere in description that DotNetZip can extract rar files. He can extract zip created with WinRAR but nowhere notice rar file can

Set password on Zip file using DotNetZip

 ̄綄美尐妖づ 提交于 2019-11-28 09:47:36
I'm using DotNetZip to zip my files, but I need to set a password in zip. I tryed: public void Zip(string path, string outputPath) { using (ZipFile zip = new ZipFile()) { zip.AddDirectory(path); zip.Password = "password"; zip.Save(outputPath); } } But the output zip not have password. The parameter path has a subfolder for exemple: path = c:\path\ and inside path I have subfolder What is wrong? Only entries added after the Password property has been set will have the password applied. To protect the directory you are adding, simply set the password before calling AddDirectory . using (ZipFile

Extract a ZIP file programmatically by DotNetZip library?

一笑奈何 提交于 2019-11-28 06:46:21
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? Oded You need to test each ZipEntry to see if you want to extract it: public void ExtractFileToDirectory(string

How can I delete a directory in a Zip file using .NET?

雨燕双飞 提交于 2019-11-28 05:01:33
问题 How would I delete a directory in a .zip and all the files in it (preferably using DotNetZip)? Right now I'm running through all the files in the zip, but it doesn't work: foreach (ZipEntry e in zip) { //If the file is in the directory I want to delete if(e.FileName.Substring(0, 9) == "FolderName/") { zip.RemoveEntry(e.FileName); } } Is there a better way, if not, how would I make this work? 回答1: First tought. Don't loop with foreach while removing elements from the collection. I will try in

Creating Zip file from stream and downloading it

半腔热情 提交于 2019-11-27 19:15:28
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); //Response.Write(zipstream); zipFile.Dispose(); the xml file in zip file is empty. Cheeso 2 things. First, if

How to zip only files and not the full path hierarchy with DotNetZip in powershell?

女生的网名这么多〃 提交于 2019-11-27 17:32:52
问题 I'm trying to zip up log using DotNetZip and powershell. The files are in C:\user\temp\logs When I loop through the logs in the directory and add them to the zip file, I end up with the folder hierarchy and the log files when I only want the log files. So the zip ends up containing: -user └temp └logs └log1.log log2.log log3.log When I want the zip file to contain is: log1.log log2.log log3.log Here is the script I'm running to test with: [System.Reflection.Assembly]::LoadFrom("c:\\\User\\bin\

DotNetZip add files without creating folders

喜你入骨 提交于 2019-11-27 13:53:44
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 How about just: zip.AddFile(file,""); or zip.AddFile(file,@"\"); Anish Ansalan zip.AddFile(file, "..\...\".ToString.Replace("..\...\", null)) This is what I did and it worked. zip.AddFile(file, "..\...\".ToString.Replace("..\...\",

Downloading of zip file through ASP.NET MVC using DotNetZip

痞子三分冷 提交于 2019-11-27 13:21:40
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("~/Directories/hello/sample.zip")); } Can someone please suggest how the zip file can be downloaded at user's