DotNetZip 是一个易于使用、免费、开源的库,用于处理 VB.NET 和其他语言中的 ZIP 文件.NET 语言。
一些示例 VB.NET 代码,用于创建 zip 文件,一次添加一个文件:
Dim ZipToCreate As String = "ex1.zip"
Dim DirectoryToZip As String = "c:\temp"
Using zip As ZipFile = New ZipFile
Dim filenames As String() = System.IO.Directory.GetFiles(DirectoryToZip)
Dim filename As String
For Each filename In filenames
zip.AddFile(filename)
Next
zip.Save(ZipToCreate)
End Using
或者,将文件添加到一组中:
Dim ZipToCreate As String = "ex1.zip"
Dim DirectoryToZip As String = "c:\temp"
Dim filenames As String() = System.IO.Directory.GetFiles(DirectoryToZip)
Using zip As ZipFile = New ZipFile
zip.AddFiles(filenames, "temp")
zip.Save(ZipToCreate)
End Using
或者,压缩整个目录或文件夹的代码:
Using zip As ZipFile = New ZipFile
zip.AddDirectory(directory)
zip.Save(targetZip)
End Using
提取 zip 文件的代码:
Dim ZipFileToExtract As String = "c:\foo.zip"
Using zip As ZipFile = ZipFile.Read(ZipFileToExtract)
Dim e As ZipEntry
For Each e In zip
' can conditionally extract here, '
' based on name, size, date, whatever.'
e.Extract
Next
End Using
使用进度条:
Imports Ionic.Zip
Module SimpleUnzip
Public Sub Unzip(ByVal ZipToUnpack As String, ByVal ExtractDirectory As String)
Try
Using zip As ZipFile = ZipFile.Read(ZipToUnpack)
Form1.ProgressBar1.Maximum = zip.Entries.Count
Dim entry As ZipEntry
For Each entry In zip
Form1.Label1.Text = entry.FileName
entry.Extract(ExtractDirectory, ExtractExistingFileAction.OverwriteSilently)
Form1.ProgressBar1.Value = Form1.ProgressBar1.Value + 1
' sleep because it's too fast otherwise.
System.Threading.Thread.Sleep(50)
Next
Form1.ProgressBar1.Value = 0
Form1.Label1.Text = "Done"
End Using
Catch ex1 As Exception
Form1.Label1.Text = ("Exception: " & ex1.ToString())
End Try
End Sub
End Module
DotNetZip 具有用于读取、保存或提取的进度事件,因此您可以在 ASP.NET 或 Windows 窗体中支持进度条。 它可以保护密码保护的 zip 文件、Unicode、ZIP64 和自解压存档。 它生成的 zip 文件与所有其他 zip 工具兼容 - WinZip、WinRAR、Windows Explorer、Pkunzip 等。有一个很好的帮助文件 (在线版本)包含大量代码示例。 还有示例可供下载。
DotNetZip is an easy-to-use, free, open-source library for handling ZIP files in VB.NET and other .NET languages.
Some sample VB.NET code, to create a zip file, adding files one at a time:
Dim ZipToCreate As String = "ex1.zip"
Dim DirectoryToZip As String = "c:\temp"
Using zip As ZipFile = New ZipFile
Dim filenames As String() = System.IO.Directory.GetFiles(DirectoryToZip)
Dim filename As String
For Each filename In filenames
zip.AddFile(filename)
Next
zip.Save(ZipToCreate)
End Using
Or, add files in a group:
Dim ZipToCreate As String = "ex1.zip"
Dim DirectoryToZip As String = "c:\temp"
Dim filenames As String() = System.IO.Directory.GetFiles(DirectoryToZip)
Using zip As ZipFile = New ZipFile
zip.AddFiles(filenames, "temp")
zip.Save(ZipToCreate)
End Using
or, Code to zip up an entire directory or folder:
Using zip As ZipFile = New ZipFile
zip.AddDirectory(directory)
zip.Save(targetZip)
End Using
Code to extract a zip file:
Dim ZipFileToExtract As String = "c:\foo.zip"
Using zip As ZipFile = ZipFile.Read(ZipFileToExtract)
Dim e As ZipEntry
For Each e In zip
' can conditionally extract here, '
' based on name, size, date, whatever.'
e.Extract
Next
End Using
Extract with a progress bar:
Imports Ionic.Zip
Module SimpleUnzip
Public Sub Unzip(ByVal ZipToUnpack As String, ByVal ExtractDirectory As String)
Try
Using zip As ZipFile = ZipFile.Read(ZipToUnpack)
Form1.ProgressBar1.Maximum = zip.Entries.Count
Dim entry As ZipEntry
For Each entry In zip
Form1.Label1.Text = entry.FileName
entry.Extract(ExtractDirectory, ExtractExistingFileAction.OverwriteSilently)
Form1.ProgressBar1.Value = Form1.ProgressBar1.Value + 1
' sleep because it's too fast otherwise.
System.Threading.Thread.Sleep(50)
Next
Form1.ProgressBar1.Value = 0
Form1.Label1.Text = "Done"
End Using
Catch ex1 As Exception
Form1.Label1.Text = ("Exception: " & ex1.ToString())
End Try
End Sub
End Module
DotNetZip has progress events for reading, saving, or extracting, so you can power progress bars in ASP.NET or Windows Forms. It does password-protected zip files, Unicode, ZIP64, and self-extracting archives. The zip files it produces are compatible with all other zip tools - WinZip, WinRAR, Windows Explorer, Pkunzip, etc. There's a good help file (online version here) with tons of code examples. There are samples available for download, too.
I do not know how to program in VB.NET. However, a search revealed an interesting link: Zip Compression VB.NET Examples. I hope it will be useful to you.
' add content of the local directory C:\Data\ '
' to the directory \Data-2010 (within the ZIP archive) '
' (ZIP archive C:\archive.zip doesn't have to exist)
ZipArchive.Add("C:\archive.zip", "C:\Data\*", "\Data-2010")
用一行代码简单地解压缩:
' extract all *.TXT files from the directory \Data-2010 (within the ZIP file) '
' to the existing local directory C:\Data '
ZipArchive.Extract("C:\archive.zip", "\Data-2010\*.html", "C:\Data")
Here are some samples of operations you are asking for:
Simple zipping files in one line of code:
' add content of the local directory C:\Data\ '
' to the directory \Data-2010 (within the ZIP archive) '
' (ZIP archive C:\archive.zip doesn't have to exist)
ZipArchive.Add("C:\archive.zip", "C:\Data\*", "\Data-2010")
Simple unzipping in one line of code:
' extract all *.TXT files from the directory \Data-2010 (within the ZIP file) '
' to the existing local directory C:\Data '
ZipArchive.Extract("C:\archive.zip", "\Data-2010\*.html", "C:\Data")
发布评论
评论(6)
DotNetZip 是一个易于使用、免费、开源的库,用于处理 VB.NET 和其他语言中的 ZIP 文件.NET 语言。
一些示例 VB.NET 代码,用于创建 zip 文件,一次添加一个文件:
或者,将文件添加到一组中:
或者,压缩整个目录或文件夹的代码:
提取 zip 文件的代码:
使用进度条:
DotNetZip 具有用于读取、保存或提取的进度事件,因此您可以在 ASP.NET 或 Windows 窗体中支持进度条。 它可以保护密码保护的 zip 文件、Unicode、ZIP64 和自解压存档。 它生成的 zip 文件与所有其他 zip 工具兼容 - WinZip、WinRAR、Windows Explorer、Pkunzip 等。有一个很好的帮助文件 (在线版本)包含大量代码示例。 还有示例可供下载。
DotNetZip is an easy-to-use, free, open-source library for handling ZIP files in VB.NET and other .NET languages.
Some sample VB.NET code, to create a zip file, adding files one at a time:
Or, add files in a group:
or, Code to zip up an entire directory or folder:
Code to extract a zip file:
Extract with a progress bar:
DotNetZip has progress events for reading, saving, or extracting, so you can power progress bars in ASP.NET or Windows Forms. It does password-protected zip files, Unicode, ZIP64, and self-extracting archives. The zip files it produces are compatible with all other zip tools - WinZip, WinRAR, Windows Explorer, Pkunzip, etc. There's a good help file (online version here) with tons of code examples. There are samples available for download, too.
看看 SharpZipLib
Have a look at SharpZipLib
我不知道如何在 VB.NET 中编程。 然而,搜索发现了一个有趣的链接:Zip Compression VB.NET Examples。 我希望它对你有用。
I do not know how to program in VB.NET. However, a search revealed an interesting link: Zip Compression VB.NET Examples. I hope it will be useful to you.
您可以使用 ICSharCode 的 SharpZipLib 库。
You can use ICSharCode's SharpZipLib library.
您可以使用我们的 Rebex ZIP 组件。
以下是您要求的一些操作示例:
用一行代码简单地压缩文件:
用一行代码简单地解压缩:
更多示例可以在 此处。
You can use our Rebex ZIP component.
Here are some samples of operations you are asking for:
Simple zipping files in one line of code:
Simple unzipping in one line of code:
More samples can be found here.
剥壳,wa-la 分两行完成
Shell it, wa-la done in two lines