ادامه مثال ها : 2 :
This example creates a zip using ZIP64 extensions. ZIP64 allows you to exceed 4gb in a zip, or 65535 entries in a zip.
 
Try
Using zip As ZipFile = New ZipFile
zip.UseZip64WhenSaving = Zip64Option.AsNecessary
zip.AddFile("c:\datafiles\RawData-2009-02-12.csv", "")
zip.AddFile("ReadMe.txt")
zip.Save(String.Format("backup-{0}.zip", DateTime.Now.ToString("yyyyMMMdd")))
End Using
Catch ex1 As Exception
Console.Error.WriteLine("exception: {0}", ex1.ToString)
End Try



Create a zip file, add a file, and also add an entry from a string. When the zip is unzipped, the content from the string will be inserted into the file "Readme.txt".
 

Dim Content As String = "This string will be the content of the Readme.txt file in the zip archive."
Using zip1 As ZipFile = New ZipFile
zip1.AddEntry("Readme.txt", "This is the readme content...")
zip1.AddFile("MyDocuments\Resume.doc", "files")
zip1.Comment = ("This zip file was created at " & DateTime.Now.ToString("G"))
zip1.Save("Content.zip")
End Using



Create a zip file, and add an entry taking content from a stream, like a MemoryStream or a FileStream.
 
Dim Content As String = "This string will be the content of the Readme.txt file in the zip archive."
Using zip1 As ZipFile = New ZipFile
zip1.AddEntry("Readme.txt", stream)
zip1.AddFile("MyDocuments\Resume.doc", "files")
zip1.Comment = ("This zip file was created at " & DateTime.Now.ToString("G"))
zip1.Save("Content.zip")
End Using

Read in a zip file, remove a few entries, save the file:
Dim sw As New System.IO.StringWriter
Using zip As ZipFile = ZipFile.Read("PackedDocuments.zip", sw)
Dim Threshold As New DateTime(2007, 7, 4)
' We cannot remove the entry from the list, within the context of
' an enumeration of said list.
' So we add the doomed entry to a list to be removed later.
' pass 1: mark the entries for removal
Dim MarkedEntries As New System.Collections.Generic.List(Of ZipEntry)
Dim e As ZipEntry
For Each e In zip
If (e.LastModified < Threshold) Then
MarkedEntries.Add(e)
End If
Next
' pass 2: actually remove the entry.
Dim zombie As ZipEntry
For Each zombie In MarkedEntries
zip.RemoveEntry(zombie)
Next
zip.Comment = "This archive has been updated."
zip.Save
End Using

Add a bunch of items, whether files or directories:
Dim itempaths As String() = _
New String() { "c:\temp\Readme.txt", _
"MyProposal.docx", _
"SupportingFiles", _
"images\Image1.jpg" }
Try
Using zip As New ZipFile(ZipToCreate, Console.Out)
Dim i As Integer
For i = 1 To itempaths.Length - 1
' will add Files or Dirs, recursing and flattening subdirectories.
zip.AddItem(itempaths(i), "flat")
Next i
zip.Save
End Using
Catch ex1 As Exception
Console.Error.WriteLine("exception: {0}", ex1.ToString())
End Try


ادامه دارد ...