There are two ways, but there is actually one way:
1. dnn is used to create the sharpziplib. dll file that comes with dnn.
/// <Summary> /// using dnn way for create ZIP file /// </Summary> /// <Param name = "FILENAME"> </param> // /<Param name = "Files"> </param> // <returns> </returns> Public static bool createzipfile2 (string filename, liftenginedocumentcollection files) {bool iscreated = false; int level = 9; string Path = filename; filestream baseoutputstream = NULL; try {baseoutputstream = file. create (PATH); zipoutput Stream zipfile = NULL; try {zipfile = new zipoutputstream (baseoutputstream); zipfile. setlevel (level); try {foreach (liftenginedocumententity entity in files) {string file = path. getfullpath (httpruntime. appdomainapppath + entity. fullpath); If (file. exists (File) {filesystemutils. addtozip (ref zipfile, file, path. getfilename (file), "") ;}} iscreated = true;} finally {}} catch (exception excep Tion1) {exception exc = exception1; dotnetnuke. Services. Exceptions. Exceptions. logexception (exception1); iscreated = false;} finally {If (zipfile! = NULL) {zipfile. finish (); zipfile. close () ;}} catch (exception exception3) {exception exception2 = exception3; dotnetnuke. services. exceptions. exceptions. logexception (exception2); iscreated = false;} finally {If (baseoutputstream! = NULL) {baseoutputstream. Close () ;}return iscreated ;}
The liftenginedocumentcollection is a collection of files. Llblgen is used for the Dal layer.
ReferenceCode:Dotnetnuke. Entities. modules.Pawriter.Createzipfile()
Method 2: Use the icsharpcode. sharpziplib. dll file. This file is newer than the built-in dnn file.
/// <Summary> // a method that creates a zip file // </Summary> /// <Param name = "zipfilestoragepath"> the storage location </Param> /// <Param name = "zipfilename"> the ZIP file name </param> /// <Param name = "filetocompress"> the file to compress </param> private void createzipfile (string zipfilestoragepath, string zipfilename, string filetocompress) {// create our ZIP file zipfile z = zipfile. create (zipfilestoragepath + zipfilename); // initialize the file so that it can accept updates Z. beginupdate (); // Add the file to the ZIP file Z. add (filetocompress); // commit the update once we are done Z. commitupdate (); // close the file Z. close ();}
This method has a problem. After a zip file is created, it will contain a directory.
Refer:
http://devpinoy.org/blogs/keithrull/archive/2008/01/25/how-to-create-zip-files-in-c-with-sharpziplib-ziplib.aspx
http://codecruncher.blogsome.com/2007/01/04/37/