C # package the folder in zip format (including all files in folders and subfolders)

Source: Internet
Author: User

I didn't like to play with a blog. I also registered this blog in the blog Park this time.
But there is no content, so I want to add anything.


Most of the gadgets recently developed by Microsoft are related to file operations/I/O. Therefore, I am going to sort out these two days and paste some things that may be shared with you, I hope it will be helpful for beginners of C!
(For more sample Code, visit the microsoft learner help website Code smaples from microsoft: http://1code.codeplex.com, download microsoft's All-in-onecode framework, this is a tool that I recently developed in Microsoft to help developers learn. It can be found that there are many sample codes for the learner's reference .)

 

C # You can call a third-party dll to package a zip file to get twice the result with half the effort, and the dll is free of charge: SharpZipLib

After downloading and decompressing the file, run the ICSharpCode command. sharpZipLib. copy the dll to the directory of the current project (if you are lazy, you can directly copy it to the binDebug directory of the current project), right-click the project reference opened by VS, and add the reference ICSharpCode. sharpZipLib. dll

Then, right-click the project opened by VS to create a class named ZipHelper. cs, clear all codes in the class, copy the following code, and paste it:

using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.IO; using System.Diagnostics; using ICSharpCode.SharpZipLib; using ICSharpCode.SharpZipLib.Zip; using ICSharpCode.SharpZipLib.Checksums; using ICSharpCode.SharpZipLib.Core;   namespace ZipOneCode.ZipProvider {      public class ZipHelper      {          /// <summary>          /// Compressed file          /// </summary>          /// <param name="sourceFilePath"></param>          /// <param name="destinationZipFilePath"></param>          public static void CreateZip( string sourceFilePath, string destinationZipFilePath)          {              if (sourceFilePath[sourceFilePath.Length - 1] != System.IO.Path.DirectorySeparatorChar)                  sourceFilePath += System.IO.Path.DirectorySeparatorChar;                ZipOutputStream zipStream = new ZipOutputStream(File.Cr

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.