MbahAgis

Create .zip file VB.Net

Sep 25th, 2021
858
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Imports System.IO
  2. Imports System.IO.Compression
  3. Public Class Form1
  4.     ''' <summary>
  5.     ''' https://docs.microsoft.com/en-us/dotnet/api/system.io.compression.ziparchive?view=net-5.0
  6.     ''' nuget library System.IO.Compression, System.IO.Compression.ZipFile (v 4.0.0), minimum ----> .net framework 4.5
  7.     ''' nuget library System.IO.Compression, System.IO.Compression.ZipFile (v 4.3.0), minimum ----> .net framework 4.6
  8.     ''' </summary>
  9.     Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
  10.         Dim inputFile As String = "D:\test\500000 Sales Records.csv"
  11.         Dim outputFile As String = "500000 Sales Records.csv"
  12.         Dim outputZip As String = "D:\test\500000 Sales Records.zip"
  13.  
  14.         Using fs As New FileStream(outputZip, FileMode.OpenOrCreate)
  15.             Using archive As New ZipArchive(fs, ZipArchiveMode.Create)
  16.                 archive.CreateEntryFromFile(inputFile, outputFile, CompressionLevel.Optimal)
  17.             End Using
  18.         End Using
  19.     End Sub
  20.  
  21. End Class
  22.  
RAW Paste Data