Asp.net C # use SharpZipLib for encryption compression, encryption, and decompression

Source: Internet
Author: User


1. Create a zip file and add the file:

The code is as follows: Copy code

Using (ZipFile zip = ZipFile. Create (@ "E: test.zip "))
{
Zip. BeginUpdate ();
Zip. Add (@ "E: file 1.txt ");
Zip. Add (@ "E: file 2.txt ");
Zip. CommitUpdate ();
}
 

2. Compress folders into files

The code is as follows: Copy code
(New FastZip (). CreateZip (@ "E: test.zip", @ "E: test", true ,"");

 

The last parameter is a filter file rule represented by a regular expression. The CreateZip method has three overloaded versions, including Directory filter parameters, File Filter parameters, and a bool type parameter used to specify whether sub-directory recursion is performed.

3. Add the file to an existing zip file.

The code is as follows: Copy code
Using (ZipFile zip = new ZipFile (@ "E: test.zip "))
{
Zip. BeginUpdate ();
Zip. Add (@ "E: test.doc ");
Zip. CommitUpdate ();
}

 

4. List zip files

The code is as follows: Copy code
Using (ZipFile zip = new ZipFile (@ "E: test.zip "))
{
String list = string. Empty;
Foreach (ZipEntry entry in zip)
    {
List + = entry. Name + "rn ";
    }
MessageBox. Show (list );
}

 

 

5. Delete a file in the zip file

The code is as follows: Copy code
Using (ZipFile zip = new ZipFile (@ "E: test.zip "))
{
Zip. BeginUpdate ();
Zip.Delete(@”test.doc ");
Zip.Delete(@”test22.txt ");
Zip. CommitUpdate ();
}

 

6. Decompress the zip file to the specified directory.

The code is as follows: Copy code

(New FastZip (). ExtractZip (@ "E: test.zip", @ "E: test ","");

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.