This article is a mirror article of machine translation, please click here to jump to the original article.

View: 41954|Reply: 0

[Source] (to).NET/C# to package the folder into a zip file

[Copy link]
Posted on 2021-4-28 13:47:05 | | |
C# packaged zip files can call ready-made third-party DLLs, which can get twice the result with half the effort, and the dll is completely free, download address: SharpZipLib

After downloading and unzipping, copy ICSharpCode.SharpZipLib.dll to the directory of the current project (if you are lazy, you can copy it directly to the bin\Debug directory of the current project), right-click on the project reference opened by VS to add the reference ICSharpCode.SharpZipLib.dll

nuget command:


Then, right-click on the project opened by VS to create a new class, name it ZipHelper.cs, empty all the code in the class, copy the following code, and paste it:

target compressed file,You cannot zip folder subdirectories, otherwise the error will be as follows:

The process cannot access the file 'D:\\Test\\ITSVSE.zip' because it is being used by another process.


To use it, after referencing using ZipOneCode.ZipProvider externally, you can call ZipHelper.CreateZip(@"D:\Temp\forzip", @"D:\Temp2\forzip.zip").

Note: Before calling, consider paying attention to some abnormal situations, such as whether the source file path exists.

MVC returns the package file:

(End)





Previous:.NET/C# Unix timestamp timestamp in detail
Next:.NET/C# Lock Principle Monitor provides an in-depth explanation
Disclaimer:
All software, programming materials or articles published by Code Farmer Network are only for learning and research purposes; The above content shall not be used for commercial or illegal purposes, otherwise, users shall bear all consequences. The information on this site comes from the Internet, and copyright disputes have nothing to do with this site. You must completely delete the above content from your computer within 24 hours of downloading. If you like the program, please support genuine software, purchase registration, and get better genuine services. If there is any infringement, please contact us by email.

Mail To:help@itsvse.com