Create a zip file. (icsharpcode. sharpziplib)

Source: Internet
Author: User
Tags create zip create zip file dnn dotnetnuke

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/

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.