Results 1 to 18 of 18

Thread: Zip files without ANY 3rd party controls (.NET 2.0)

  1. #1

    Thread Starter
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373

    Zip files without ANY 3rd party controls (.NET 2.0)

    Lots of people have asked about zipping files up via code. There are solutions that involve 3rd party components, running winzip or winrar in a command line silently, etc...

    some of these work just fine, but what if you want to do it from with the framework itself, without leaving the .NET framework.

    Well if VB had a ZIP class, we would all know about it already... but how about JAVA? J# is a built in part of the .NET framework, and it also has ZIP capabilities built right in. So by adding a reference to one of the .NET java libraries (vjslib.dll) you can add zip support.

    I have created a class in VB.NET that will do just this. Attached is a sample project to show you how it is done.

    I plan to add more functionality to the class when I have time, but most of the time, people are just looking to ZIP files up, and this will do just that.

    the method takes only 2 params, one is a string array of the files you want to zip, and the other is the name of the zip file.

    You should pass full paths (not just file names) for both params. The sample project will demonstrate how to use it. I hope this is useful to other people.


    REMARKS:
    I have not tested this on older .NET framework versions, and I have heard there might be issues if used on .NET 1.0 or 1.1, when zipping exe files. I can not confirm this just yet.

    The sample project has a test.doc and test.txt in the debug bin folder. These are the files that the sample project zips up. They are simply docs that contain the alphabet a whole bunch of times (to give the file some substance so it can be compacted)

    Thanks for looking!
    Attached Files Attached Files

  2. #2
    Hyperactive Member OMITT3D's Avatar
    Join Date
    Mar 2006
    Posts
    368

    Re: Zip files without ANY 3rd party controls (.NET 2.0)

    Hi, what about unzipping the files?

  3. #3
    Frenzied Member MrGTI's Avatar
    Join Date
    Oct 2000
    Location
    Ontario, Canada
    Posts
    1,277

    Cool Re: Zip files without ANY 3rd party controls (.NET 2.0)

    For those interested, if you wanted to include the complete filepath of a file when using this code (instead of just the filename), you need to make a minor change. In the ZipUtility.vb file, Find this line of code:
    VB Code:
    1. MyZipEntry = New ZipEntry(New IO.FileInfo(sCompleteFilePath).Name)
    Change it to read as so:
    VB Code:
    1. MyZipEntry = New ZipEntry(New IO.FileInfo(sCompleteFilePath).FullName)
    Thanks to kleinma for pointing that out.
    .
    ~Peter


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

    Re: Zip files without ANY 3rd party controls (.NET 2.0)

    It doesn't work if you use the fullname.
    I don't live here any more.

  5. #5
    PowerPoster VBDT's Avatar
    Join Date
    Sep 2005
    Location
    CA - USA
    Posts
    2,922

    Re: Zip files without ANY 3rd party controls (.NET 2.0)

    Last updated: 02/19/2007

    I extended the project with some functions. See the update list.

    Update list:
    • In addition to compressing files it will compresses folders with its sub folders and files.
    • Decompresses files and folders with its sub folders and files.
    • Adds folders and files to a zip file.
    • Removes files from a zip file.
    • Provides an event for progress change. <---New
    • Provides an event for process complete. <---New

    You just need to use the 'ZipUtility' class from the project.
    Attached Images Attached Images   
    Attached Files Attached Files

  6. #6
    New Member
    Join Date
    Apr 2007
    Posts
    1

    Angry Re: Zip files without ANY 3rd party controls (.NET 2.0)

    I just wanted to point out that the java lib files are not deployed with the 2.0 framework. They are deployed with Visual Studio....so....to all looking at this for "Zip files without ANY 3rd party controls" don't waste your time as the java lib files will pad your installation by roughly 1500KB. I'm sure a 3rd party zip component is out there that has a much smaller foot print.


  7. #7

    Thread Starter
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373

    Re: Zip files without ANY 3rd party controls (.NET 2.0)

    they aren't deployed with the .NET framework, but they aren't only deployed with a visual studio isntall. MS does have a redist package you can include with the .NET 2.0 framework.

    I agree there may be a component that has a smaller footprint, but most decent ones I have seen are at a cost. I would hope built in zip classes will make their way right into the standard framework before long though..

    The 2.0 framework already did add a GZip class that is right in system.dll in the System.IO.Compression namespace...

  8. #8
    Hyperactive Member
    Join Date
    Mar 2006
    Posts
    413

    Re: Zip files without ANY 3rd party controls (.NET 2.0)

    I like to see lots of approches, but I used a library that was from c# and added very little to the size.

    #ZipLib
    Visual Studio .NET 2005/.NET Framework 2.0

  9. #9
    New Member
    Join Date
    May 2007
    Posts
    1

    Re: Zip files without ANY 3rd party controls (.NET 2.0)

    Hi Kleinma, I am using your project to deal with a large number of zip files and all is working great. But I have now hit a problem with a corrupted zip file. The decompress fails and when i try to move or delete the file i get an error saying the file is locked by another process. This obviously gets cleared when the program is exited, but i need to deal with this in code.

    Can you help me?

    Many thanks

  10. #10
    New Member
    Join Date
    Jun 2007
    Posts
    6

    Re: Zip files without ANY 3rd party controls (.NET 2.0)

    I had only one problem with this. In the Private Overloads Sub Compress() method, I had to change the last ElseIf and comment out the If part:

    Else 'If (fsInfo.Attributes And IO.FileAttributes.Archive) <> 0 Then

    Because it was skipping one of my files.

    Also, I changed the "paths" variable from an array of String to an ArrayList. The ArrayList makes it easier to dynamically add file paths to the list of files.

  11. #11
    PowerPoster JuggaloBrotha's Avatar
    Join Date
    Sep 2005
    Location
    Lansing, MI; USA
    Posts
    4,286

    Re: Zip files without ANY 3rd party controls (.NET 2.0)

    Quote Originally Posted by jsweeney
    I had only one problem with this. In the Private Overloads Sub Compress() method, I had to change the last ElseIf and comment out the If part:

    Else 'If (fsInfo.Attributes And IO.FileAttributes.Archive) <> 0 Then

    Because it was skipping one of my files.

    Also, I changed the "paths" variable from an array of String to an ArrayList. The ArrayList makes it easier to dynamically add file paths to the list of files.
    If you're using .Net 2.0 forget about the lame ArrayList, use List(Of String) instead (or List(of Integer), etc...)
    Currently using VS 2015 Enterprise on Win10 Enterprise x64.

    CodeBank: All ThreadsColors ComboBoxFading & Gradient FormMoveItemListBox/MoveItemListViewMultilineListBoxMenuButtonToolStripCheckBoxStart with Windows

  12. #12
    New Member
    Join Date
    Oct 2008
    Posts
    2

    Re: Zip files without ANY 3rd party controls (.NET 2.0)

    I have a case where my users require to keep the original file's Date/Time Modified value unchanged in the ZIP file after the process occurs... I have the code you supplied embedded and functioning wonderfully, but as I mentioned, the files within the ZIP contain the Date/Time of the actual ZIPPING process, not their originals...

    Is there a way that I can make this happen??!!

    Much appreciated and thanks for the assistance!

  13. #13
    New Member
    Join Date
    Oct 2008
    Posts
    2

    Re: Zip files without ANY 3rd party controls (.NET 2.0)

    Any news/update about functionality to append to an existing ZIP file??!!

  14. #14

    Thread Starter
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373

    Re: Zip files without ANY 3rd party controls (.NET 2.0)

    No. I don't plan on any further work on this code example because it used the J# runtime which has since been discontinued from Microsoft's language line, and will have no future development down the line from Microsoft.

  15. #15
    New Member
    Join Date
    Mar 2009
    Posts
    6

    Re: Zip files without ANY 3rd party controls (.NET 2.0)


  16. #16
    PowerPoster JuggaloBrotha's Avatar
    Join Date
    Sep 2005
    Location
    Lansing, MI; USA
    Posts
    4,286

    Re: Zip files without ANY 3rd party controls (.NET 2.0)

    Quote Originally Posted by imoq172 View Post
    ...but that's a 3rd party control...
    Currently using VS 2015 Enterprise on Win10 Enterprise x64.

    CodeBank: All ThreadsColors ComboBoxFading & Gradient FormMoveItemListBox/MoveItemListViewMultilineListBoxMenuButtonToolStripCheckBoxStart with Windows

  17. #17

    Thread Starter
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373

    Re: Zip files without ANY 3rd party controls (.NET 2.0)

    this thread is really old. I wouldn't consider the original code to be a viable solution anymore...

  18. #18
    Addicted Member rkeslar's Avatar
    Join Date
    Jul 2009
    Location
    Pittsburgh, PA
    Posts
    145

    Re: Zip files without ANY 3rd party controls (.NET 2.0)

    Quote Originally Posted by kleinma View Post
    this thread is really old. I wouldn't consider the original code to be a viable solution anymore...
    What would you recommend doing now instead? I know there is a Packaging namespace in .NET 3.0 and above, but I'm writing a .NET 2.0 app and trying to stay away from 3rd party controls to save money and confusion. I like the example. It works great and it was easy to implement too.

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