Dotnetzip File compression and decompression

Source: Internet
Author: User

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/

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.