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 ();}