Compress Files

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, 
            Dim file = archive.CreateEntryFromFile(sourceFileName, 
        End Using
    End If
End Sub



Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s