what is new - .net 4.5: Simple zip examples
2013-01-24 00:00
423 查看
As in
what is new in .net 4.5 framework, one is mentioned that the System.IO.Compression names has improved so that the zip reduce the size of generated files. In .NET 4.5, the namespace that takes care of compression is System.IO.Compression, and you may need to use the System.IO.Compression.FileSystem.dll;
For some very simple use case, you can use the following method to zip files. here is the
ZipFile class where you can perform the very basic compression and extraction with .
the source code for the example is as follow.
DeflateStream
GzipStream
what is new in .net 4.5 framework, one is mentioned that the System.IO.Compression names has improved so that the zip reduce the size of generated files. In .NET 4.5, the namespace that takes care of compression is System.IO.Compression, and you may need to use the System.IO.Compression.FileSystem.dll;
For some very simple use case, you can use the following method to zip files. here is the
ZipFile class where you can perform the very basic compression and extraction with .
the source code for the example is as follow.
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; // you will need to use System.IO.Compression.FileSystem.dll using System.IO.Compression; using System.IO; namespace ZipCompression { public class SimpleZip { public static void SimpleZipFile(string[] args) { string startPath = @"U:\docs\blogs"; string zipPath = @"U:\temp\result.zip"; string extractPath = @"U:\temp\extract"; try { if (!Directory.Exists(startPath)) { Console.Error.WriteLine("Directory {0} does not exist!", startPath); } if (File.Exists(zipPath)) { // Console.WriteLine("Removing existing zip file - {0}", zipPath); File.Delete(zipPath); } if (Directory.Exists(extractPath)) { Console.WriteLine("Removing existing extract directory - {0}", extractPath); Directory.Delete(extractPath, true); } ZipFile.CreateFromDirectory(startPath, zipPath); Console.WriteLine("zip contents completed"); ZipFile.ExtractToDirectory(zipPath, extractPath); Console.WriteLine("Extracat completed"); } catch { Console.WriteLine("Failed to run the zip examples"); throw; } } } }Extended reading:
DeflateStream
GzipStream
相关文章推荐
- what is new - .NET 4.5: review of the ThreadLocal
- .NET Versioning and Multi-Targeting - .NET 4.5 is an in-place upgrade to .NET 4.0
- Beatmod feat.Yoshi Honeycomb what's is the the new RamHacked SPL/Radio
- What is new in the .net framework 3.5?
- What is the difference between new and malloc()?
- What is the difference between new/delete and malloc/free?
- What’s New For Parallelism in .NET 4.5
- NSLock(Mac OS X (Cocoa) ) — Simple Explanation of What It Is and Why You Need It
- What is the difference between Simple, Advanced and Parameter data sets?
- What Is SNMP(Simple Network Management Protocol )
- Mini-SQL: what is new?
- What is new in WebSphere Application Server 8.0
- Ubuntu 12 修改当前用户密码:new password is too simple
- What is MPEG-4 Simple Profile Level 0?
- What is new and important info you can get from JavaOne 2007
- What is new for DataStage 8 on the Information Server
- What Is New in MySQL 5.7(MySQL 5.7的新特性)
- android.util.AndroidRuntimeException Calling startActivity() from outside of an Activity context requires the FLAG_ACTIVITY_NEW_TASK flag. Is this really what you want? com.uethinking.microvideo.manag
- WWDC 2012 Session笔记——200 What is new in Cocoa Touch
- What is new in Android security (M and N Version) - Google I/O 2016 翻译