I want to compress a file and a directory in C#. I found some solution in Internet but they are so complex and I couldn't run them in my project. Can anybody suggest me a clear and effective solution?
相关问题
- Sorting 3 numbers without branching [closed]
- Graphics.DrawImage() - Throws out of memory except
- Generic Generics in Managed C++
- Why am I getting UnauthorizedAccessException on th
- 求获取指定qq 资料的方法
I'm adding this answer as I've found an easier way than any of the existing answers:
Code:
If you don't want the original folder structure mirrored in the zip file, then look at the overrides for AddFile() and AddFolder() etc.
Using DotNetZip http://dotnetzip.codeplex.com/, there's an AddDirectory() method on the ZipFile class that does what you want:
Bonne continuation...
There is a built-in class in
System.IO.Packaging
called theZipPackage
:http://msdn.microsoft.com/en-us/library/system.io.packaging.zippackage(v=vs.100).aspx
Use http://dotnetzip.codeplex.com/ to ZIP files or directory, there is no builtin class to do it directly in .NET
http://www.icsharpcode.net/opensource/sharpziplib/
For .Net Framework 4.5 this is the most clear example I found:
You'll need to add a reference to System.IO.Compression.FileSystem
From: https://docs.microsoft.com/en-us/dotnet/standard/io/how-to-compress-and-extract-files