Thứ Hai, 5 tháng 11, 2012

Nén và giải nén File trong C# .NET 4.5

Phiên bản .NET Framework 4.5 đã cung cấp thư viện hỗ trợ nén và giải nén file trong NameSpace System.IO.Compression mà các phiên bản .NET Framework trước đó chưa cung cấp.

Trước hết cần đảm bảo .NET 4.5 đã được cài đặt và add reference  System.IO.Compression.FileSystem

  1. //nén thư mục TestZipFile thành TestZipFile.zip  
  2. System.IO.Compression.ZipFile.CreateFromDirectory("C:\\Users\\Phong\\Desktop\\TestZipFile""C:\\Users\\Phong\\Desktop\\TestZipFile.zip");  
  3.   
  4. //giải nén TestZipFile.zip ra thư mục TestExtract  
  5. System.IO.Compression.ZipFile.ExtractToDirectory("C:\\Users\\Phong\\Desktop\\TestZipFile.zip""C:\\Users\\Phong\\Desktop\\TestExtract");  
Xem thêm các tính năng mới trong .NET 4.5 trên MSDN.

Không có nhận xét nào :

Đăng nhận xét