Download the official source code: http://files.cnblogs.com/zhengjuzhuan/dotnetziplib-devkit-v1%1%.8.zip
Code
Dotnetzip is a short and easy-to-use. Net class library used to operate ZIP files. It supports any. Net Language and allows you to easily create, read, and update ZIP files. It can also be used in. netcompact framework.
Below are some simple examples:
1 . Encrypted compression:
Using (Zipfile zip = New Zipfile ())
{
Zip. Password = Spassword; // Set pwd
Zip. adddirectory (szipdir );
Zip. Save (ssavepath + @" \ " + Ssavename );
}
2 . Add to the compressed file:
Using (Zipfile zip = New Zipfile ( " Backup.zip " ))
{
Zip. Password = " 123456! " ;
Zip. AddFile ( " Readme.txt " );
Zip. AddFile ( " 7440-n49th.png " );
Zip. AddFile ( " 2005_annual_report.pdf " );
Zip. Save ();
}
3 . Decompress to the specified directory:
Using (Zipfile zip = Zipfile. Read ( " D: \ test \ 2007.zip " ))
{
Foreach (Zipentry E In Zip)
{
Console. writeline ( " File Name: {0} " , E. filename );
Console. writeline (E. Comment );
E. Extract ( " D: \ test \ pwdata " , True ); // Overwrite = true
}
}
4 . Chinese garbled problem system. Text. encoding. Default
Using (Zipfile zip = New Zipfile (system. Text. encoding. Default ))
{
Foreach (VAR F In Filestoinclude)
{
Zip. AddFile (F, " Files " );
}
Zip. addentry ( " Readme.txt " , "" , Readmetext );
Zip. Save (response. outputstream );
}
5 .Asp.net package and download
Ionic. Zip. zipfile zipfilepack = New Ionic. Zip. zipfile (system. Text. encoding. Default );
String Souredirectory = This . Mappath ( " Filepack/test No. 1/temp " );
String Sourepath = This . Mappath ( " Filepack/Development Center bbbb.doc " );
Zipfilepack. adddirectory (souredirectory, " Temp " ); // Files and folders in the folder are compressed to the temp directory.
Zipfilepack. AddFile (sourepath, " ABC " ); // Files are compressed to the ABC directory.
Zipfilepack. AddFile (sourepath, "" ); // File compression to the root directory
Response. Clear ();
Response. bufferoutput = False ;
Response. contentencoding = System. Text. encoding. utf8;
Response. contenttype = " Application/zip " ;
Response. addheader ( " Content-Disposition " , " Filename = " + Guid. newguid (). tostring () + " . Zip " );
Zipfilepack. Save (response. outputstream );
Response. Close ();
Open source home: http://dotnetzip.codeplex.com/