There are a number of ways to compress things in .NET, but I found out that only the code below works for files. I wrote the code below for my console apps .NET back utility.
Imports System.IO.Compression
''' <summary>
''' Compresses the file.
''' </summary>
''' <param name="sourceFileName">Name of the source file.</param>
''' <param name="destinationFileName">Name of the destination file
including extension.</param>
Public Sub CompressFile(sourceFileName As String,
destinationFileName As String)
If File.Exists(sourceFileName) Then
Using archive = ZipFile.Open(destinationFileName,
ZipArchiveMode.Create)
Dim file = archive.CreateEntryFromFile(sourceFileName,
Path.GetFileName(destinationFileName),
CompressionLevel.Optimal)
End Using
End If
End Sub
Discover more from dotNetTips.com
Subscribe to get the latest posts sent to your email.
