C # Batch File compression

Source: Internet
Author: User

C # Batch File compression
Today, I changed the function of a website. The website provides some materials. Each page corresponds to a set of materials. If a Member downloads the materials one by one, the website interaction is a little poor. The modified content is to provide a button and click the button to package and download the image and website information. Idea: first, generate website information by format, traverse the directory to find all the materials, package these files, and use response to output. The implementation of file packaging is implemented using the DotNetZip code of the external open source Library: Create an asp.net blank project, create a page, and reference the Ionic under the DotNetZip library. zip. dll references Ionic in the page. zip namespace using Ionic. zip; Code for batch compression: add the copy code in Page_Load if (! Page. isPostBack) {Response. clear (); Response. bufferOutput = false; string [] files = Directory. getFiles (Server. mapPath ("img/"); // The website file generates a readme.txt file String readmeText = String. format ("README. TXT "+ Environment. newLine + "http://shandongit.com"); Response. contentType = "application/zip"; Response. addHeader ("content-disposition", "inline; filename = \" "+ String. format ("archive-00000).zip", DateTime. now. toString ("yyyy-MMM-dd-HHmmss") + "\"); // batch compression operation using (ZipFile zip = new ZipFile ()) {// the Readme.txt file will not be password-protected. zip. addEntry ("Readme.txt", readmeText, Encoding. default); zip. password = "shandongit.com"; zip. encryption = EncryptionAlgorithm. winZipAes256; // filesToInclude is a string [] or List <String> zip. addFiles (files, "files"); zip. save (Response. outputStream);} Response. close ();}

Related Article

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.