Avatar of targunp
targunp
 asked on

How do you zip a folder using VB.net?

Is there a way to do this without using a 3rd party application?

Thanks
Phil
Visual Basic.NET.NET ProgrammingScripting Languages

Avatar of undefined
Last Comment
targunp

8/22/2022 - Mon
EYoung

Here is a way to zip using a Process:

    Private Sub srZip_CSV_File()
        'Zip RetailCustLineData.csv to RetailCustLineData.zip and pause until completed before continuing
        Dim P As New Process
        P.StartInfo.FileName = "C:\Program Files\WinZip\WINZIP32.EXE"
        P.StartInfo.Arguments = "-min -a C:\FTP-Data\Icentrix\RetailCustLineData.zip C:\FTP-Data\Icentrix\RetailCustLineData.csv"
        P.Start()
        P.WaitForExit()
        ' ...continue with other stuff...
    End Sub
EYoung

Be sure to change this line to zip a folder:  (example)

P.StartInfo.Arguments = "-min -a C:\FTP-Data\Icentrix\<folder_name.zip> C:\FTP-Data\Icentrix\*.*"

Change it to your names.
AngryBinary

There aren't any built-in .NET classes that handle ZIP compression. Also, the "built-in" zip compression for windows (Right click -> send to -> Compressed Folder) does not have a command line interface unless you've downloaded the MS support tool kit.

So, you will either need to download a 3rd party .NET zip library (such as http://www.icsharpcode.net/opensource/sharpziplib/ - if you download the compiled assembly, it will work with a VB.NET application) or make a call to a 3rd party zip utility with a command line interface  (or Microsoft's COMPRESS utility, if you do have the support tools installed) using "Process.Start(executableFile, args)".
Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy
Éric Moreau

ASKER CERTIFIED SOLUTION
raja_ind82

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
targunp

ASKER
Google gzip, that is the best solution.
targunp

ASKER
Gzip is better, the example posted shows you how to pack a file, not pack and compress. Still thank you for your help
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.