Results 1 to 21 of 21

Thread: Zip for VB.Net? [Resolved]

  1. #1

    Thread Starter
    Frenzied Member dinosaur_uk's Avatar
    Join Date
    Sep 2004
    Location
    Jurassic Park
    Posts
    1,098

    Resolved Zip for VB.Net? [Resolved]

    Hi there,

    I have been looking for a way to zip files and directories up within vb.net.

    I have heard of the CdSharp open source libraries but have been unable to get it to work. I have also heard of Xceed Zip class but that cost alot for something simple which i need to get done.

    Has anyone got the zip to work? Can i make use of the in build zip in winXP?

    Cheers
    Last edited by dinosaur_uk; Jun 16th, 2005 at 03:05 AM.

  2. #2
    type Woss is new Grumpy; wossname's Avatar
    Join Date
    Aug 2002
    Location
    #!/bin/bash
    Posts
    5,682

    Re: Zip for VB.Net?

    If you have winzip on your machine then you could always use that (with command line arguments) to do it. Winzip has comprehensive commandline support and should work without any visible interface.

    You couls call it with

    VB Code:
    1. Process.Start("Winzip.exe myfile.txt myzip.zip /args go here")
    I don't live here any more.

  3. #3
    Frenzied Member DeadEyes's Avatar
    Join Date
    Jul 2002
    Posts
    1,196

    Re: Zip for VB.Net?

    you could have a look at
    #ziplib
    It's released under the GPL, however I haven't tried it myself.

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Zip for VB.Net?

    Some suggestions in this thread.

  5. #5

    Thread Starter
    Frenzied Member dinosaur_uk's Avatar
    Join Date
    Sep 2004
    Location
    Jurassic Park
    Posts
    1,098

    Re: Zip for VB.Net?

    cheers...i will try the winzip route

  6. #6
    PowerPoster 2.0 Negative0's Avatar
    Join Date
    Jun 2000
    Location
    Southeastern MI
    Posts
    4,367

    Re: Zip for VB.Net?

    I usually recommend the #zip utility when this question comes up. It's easy to use and doesn't require winzip on the user's machine.

    Also, I think if the user has an unregistered version of Winzip, they may be prompted with the Evaluation Version box.

  7. #7
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Zip for VB.Net?

    I think it unwise to assume anything about the destination machine that is not specifically under your control. If you know for sure that WinZip will be there then great, but otherwise...

  8. #8

    Thread Starter
    Frenzied Member dinosaur_uk's Avatar
    Join Date
    Sep 2004
    Location
    Jurassic Park
    Posts
    1,098

    Re: Zip for VB.Net?

    Quote Originally Posted by wossname
    If you have winzip on your machine then you could always use that (with command line arguments) to do it. Winzip has comprehensive commandline support and should work without any visible interface.

    You couls call it with

    VB Code:
    1. Process.Start("Winzip.exe myfile.txt myzip.zip /args go here")
    The thing is that i would like to be able to change the name of the file and what i am zipping but it does not work?

    VB Code:
    1. Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    2.         Dim source As String
    3.         source = "C:\Program Files\WinZip\WZZIP.EXE -rp hi.zip " & DatabasePath
    4.         Process.Start(source)
    5.     End Sub

    Any ideas how to string build it up?

  9. #9

    Thread Starter
    Frenzied Member dinosaur_uk's Avatar
    Join Date
    Sep 2004
    Location
    Jurassic Park
    Posts
    1,098

    Re: Zip for VB.Net?

    Not sure if this is the right way, but i have done it via a batch file

    VB Code:
    1. Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    2.         Dim source As New System.Text.StringBuilder
    3.         If IO.File.Exists(Application.StartupPath & "\run.bat") Then
    4.             IO.File.Delete(Application.StartupPath & "\run.bat")
    5.         End If
    6.  
    7.         Dim sw As StreamWriter = IO.File.CreateText(Application.StartupPath & "\run.bat")
    8.         source.Append("C:\Program Files\WinZip\WZZIP.EXE -rp hi.zip " & DatabasePath)
    9.         sw.WriteLine(source.ToString)
    10.         sw.Close()
    11.         Process.Start(Application.StartupPath & "\run.bat")
    12.         IO.File.Delete(Application.StartupPath & "\run.bat")
    13.     End Sub

  10. #10

    Thread Starter
    Frenzied Member dinosaur_uk's Avatar
    Join Date
    Sep 2004
    Location
    Jurassic Park
    Posts
    1,098

    Re: Zip for VB.Net?

    I have made a temp batch file and have run it then deleted it after usage....

    Anyone has a better solution?

  11. #11

    Thread Starter
    Frenzied Member dinosaur_uk's Avatar
    Join Date
    Sep 2004
    Location
    Jurassic Park
    Posts
    1,098

    Re: Zip for VB.Net?

    Oh by the way....if your command line has spaces in it ,,,you have to put " before and after the path...

    Corrected code:
    VB Code:
    1. Dim sw As StreamWriter = IO.File.CreateText(Application.StartupPath & "\run.bat")
    2.             'For the winzip, we will potentially put this path into a config file.
    3.             source.Append(Chr(34) & "C:\program files\winzip\WZZIP.EXE" & Chr(34) & " -rp ")
    4.             source.Append(Chr(34) & Me.txtOutputFolder.Text)
    5.             source.Append(Date.Now.Day & "-")
    6.             source.Append(Date.Now.Month & "-")
    7.             source.Append(Date.Now.Now.Year & "-Database.zip" & Chr(34) & " ")
    8.             source.Append(Chr(34) & DatabasePath & Chr(34))
    9.             sw.WriteLine(source.ToString)
    10.             sw.Close()
    11.             Process.Start(Application.StartupPath & "\run.bat")
    12.             IO.File.Delete(Application.StartupPath & "\run.bat") 'Remove the file.

  12. #12
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Zip for VB.Net?

    When calling Process.Start with one argument, you must use the file name only. If you are trying to start a process and you want to pass commandline arguments to it, you use an overload of Process.Start that takes two arguments. The first is the file name and the second is the commandline arguments.
    VB Code:
    1. Process.Start("C:\Program Files\WinZip\WZZIP.EXE", "-rp hi.zip " & DatabasePath)

  13. #13
    Frenzied Member toecutter's Avatar
    Join Date
    Apr 2006
    Location
    Brisbane, Australia
    Posts
    1,160

    Re: Zip for VB.Net? [Resolved]

    Is this 2003 code?

  14. #14
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Zip for VB.Net? [Resolved]

    Yes, that is the same code in 2003.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  15. #15
    Frenzied Member toecutter's Avatar
    Join Date
    Apr 2006
    Location
    Brisbane, Australia
    Posts
    1,160

    Re: Zip for VB.Net? [Resolved]

    rgr
    What is the DatabasePath variable?

  16. #16
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Zip for VB.Net? [Resolved]

    That is the name of the file to zip I'd assume. Just check the commandline arguments of the WZZIP.EXE by typing at the command prompt "WZZIP.EXE /?"
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  17. #17
    Frenzied Member toecutter's Avatar
    Join Date
    Apr 2006
    Location
    Brisbane, Australia
    Posts
    1,160

    Re: Zip for VB.Net? [Resolved]

    Quote Originally Posted by RobDog888
    That is the name of the file to zip I'd assume. Just check the commandline arguments of the WZZIP.EXE by typing at the command prompt "WZZIP.EXE /?"
    Not sure what you mean by that.

    I found this
    Adding Files

    "The command format is:

    winzip32 [-min] action [options] filename[.zip] files

    where:

    -min specifies that WinZip should run minimized. If -min is specified, it must be the first command line parameter.

    action
    -a for add, -f for freshen, -u for update, and -m for move. You must specify one (and only one) of these actions. The actions correspond to the actions described in the section titled "Add dialog box options" in the online manual.

    options
    -r corresponds to the Include subfolders checkbox in the Add dialog and causes WinZip to add files from subfolders. Folder information is stored for files added from subfolders. If you add -p, WinZip will store folder information for all files added, not just for files from subfolders; the folder information will begin with the folder specified on the command line.

    -ex, -en, -ef, -es, and -e0 determine the compression method: eXtra, Normal, Fast, Super fast, and no compression. The default is "Normal". -hs includes hidden and system files. Use -sPassword to specify a case-sensitive password. The password can be enclosed in quotes, for example, -s"Secret Password".

    filename.zip
    Specifies the name of the Zip file involved. Be sure to use the full filename (including the folder).

    files
    Is a list of one or more files, or the @ character followed by the filename containing a list of files to add, one filename per line. Wildcards (e.g. *.bak) are allowed.
    They way i followed it dosn't seem to work correctly

    Code:
       Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
                 Process.Start("C:\Program Files\WinZip\WZZIP.EXE", "-rp C:\Documents and Settings\toe\Desktop\WinZip\Document.zip" & "Document.txt")
        End Sub
    Error:
    "System cannot find the find the file specified"

    While trying to zip this file

    ("C:\Documents and Settings\toe\Desktop\WinZip\Document.txt")

    Can you see what iam doing wrong?

    thanks
    toe

  18. #18
    Frenzied Member toecutter's Avatar
    Join Date
    Apr 2006
    Location
    Brisbane, Australia
    Posts
    1,160

    Re: Zip for VB.Net? [Resolved]

    mmmm, maybe it only works with the pro version

    The WinZip Command Line Support Add-On is a FREE add-on for users of WinZip Pro with a valid license.
    winzip.com

  19. #19
    PowerPoster 2.0 Negative0's Avatar
    Join Date
    Jun 2000
    Location
    Southeastern MI
    Posts
    4,367

    Re: Zip for VB.Net? [Resolved]

    As I stated in my post a few years ago, if you are trying to Zip from .Net, you can use the #Ziplib library. It is free.

    http://www.icsharpcode.net/OpenSource/SharpZipLib/

  20. #20
    Frenzied Member
    Join Date
    Jul 2006
    Location
    MI
    Posts
    2,012

    Re: Zip for VB.Net? [Resolved]

    This code will zip a folder of files using WinXP built in compression:

    Code:
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    
            Dim srcfolderString As String
            Dim dstfolderString As String = "c:\ZippedFolder.zip"
    
            'get folder to zip
            Dim fbd As New FolderBrowserDialog
            If fbd.ShowDialog() = Windows.Forms.DialogResult.OK Then
    
                srcfolderString = fbd.SelectedPath
    
                'create empty zip file
                Dim fileContents() As Byte = {80, 75, 5, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
                My.Computer.FileSystem.WriteAllBytes(dstfolderString, fileContents, False)
    
                Dim objShell As New Shell32.ShellClass
                Dim objFolderSrc As Shell32.Folder
                Dim objFolderDst As Shell32.Folder
                Dim objFolderItems As Shell32.FolderItems
    
                objFolderSrc = objShell.NameSpace(srcfolderString)
                objFolderDst = objShell.NameSpace(dstfolderString)
                objFolderItems = objFolderSrc.Items
                objFolderDst.CopyHere(objFolderItems, 20)
    
            End If
    You also need to add a reference to Microsoft Shell Controls And Automation

  21. #21
    Frenzied Member toecutter's Avatar
    Join Date
    Apr 2006
    Location
    Brisbane, Australia
    Posts
    1,160

    Re: Zip for VB.Net? [Resolved]

    Quote Originally Posted by nbrege
    This code will zip a folder of files using WinXP built in compression:

    Code:
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    
            Dim srcfolderString As String
            Dim dstfolderString As String = "c:\ZippedFolder.zip"
    
            'get folder to zip
            Dim fbd As New FolderBrowserDialog
            If fbd.ShowDialog() = Windows.Forms.DialogResult.OK Then
    
                srcfolderString = fbd.SelectedPath
    
                'create empty zip file
                Dim fileContents() As Byte = {80, 75, 5, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
                My.Computer.FileSystem.WriteAllBytes(dstfolderString, fileContents, False)
    
                Dim objShell As New Shell32.ShellClass
                Dim objFolderSrc As Shell32.Folder
                Dim objFolderDst As Shell32.Folder
                Dim objFolderItems As Shell32.FolderItems
    
                objFolderSrc = objShell.NameSpace(srcfolderString)
                objFolderDst = objShell.NameSpace(dstfolderString)
                objFolderItems = objFolderSrc.Items
                objFolderDst.CopyHere(objFolderItems, 20)
    
            End If
    You also need to add a reference to Microsoft Shell Controls And Automation

    Thanks for that

    What will the end user need to unzip a folder using WinXP built in compression: EG net frame work 2.0 only?

    I tried your example on a new folder i placed on the desktop and got "Access to the path 'C:\Documents and Settings\toe\Desktop\New Folder' is denied."

    Any ideas?


    Negative0

    I will check that out what you stated n your post a few years ago if i carnt use the WinXp built in compression.

    thanks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width