Results 1 to 4 of 4

Thread: Code for zip a file

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Apr 2010
    Posts
    478

    Code for zip a file

    I want to learn zip file from the link below but got an error said that "ZipArchive is not defined"
    How to fix it?
    (I used vs2015, win7, framework 4.5)

    https://msdn.microsoft.com/en-us/lib...v=vs.110).aspx

    Imports System.IO
    Imports System.IO.Compression

    Module Module1

    Sub Main()
    Dim zipPath As String = "c:\example\start.zip"
    Dim extractPath As String = "c:\example\extract"

    Using archive As ZipArchive = ZipFile.OpenRead(zipPath)
    For Each entry As ZipArchiveEntry In archive.Entries
    If entry.FullName.EndsWith(".txt", StringComparison.OrdinalIgnoreCase) Then
    entry.ExtractToFile(Path.Combine(extractPath, entry.FullName))
    End If
    Next
    End Using
    End Sub

    End Module

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,299

    Re: Code for zip a file

    It's of no use importing the namespace that a type is a member of if you haven't referenced the assembly it's declared in. Have you done that? The MSDN documentation for every .NET type tells you what assembly it's declared in and what namespace it's a member of. You should read the documentation for the ZipArchive class.

  3. #3
    Angel of Code Niya's Avatar
    Join Date
    Nov 2011
    Posts
    8,598

    Re: Code for zip a file

    Wait.....did MS buy DotNetZip? That API looks a lot like DotNetZip's API.
    Treeview with NodeAdded/NodesRemoved events | BlinkLabel control | Calculate Permutations | Object Enums | ComboBox with centered items | .Net Internals article(not mine) | Wizard Control | Understanding Multi-Threading | Simple file compression | Demon Arena

    Copy/move files using Windows Shell | I'm not wanted

    C++ programmers will dismiss you as a cretinous simpleton for your inability to keep track of pointers chained 6 levels deep and Java programmers will pillory you for buying into the evils of Microsoft. Meanwhile C# programmers will get paid just a little bit more than you for writing exactly the same code and VB6 programmers will continue to whitter on about "footprints". - FunkyDexter

    There's just no reason to use garbage like InputBox. - jmcilhinney

    The threads I start are Niya and Olaf free zones. No arguing about the benefits of VB6 over .NET here please. Happiness must reign. - yereverluvinuncleber

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

    Re: Code for zip a file

    What I do is have 7zip installed (it's free) then simply call it in .Net passing it the parameters on the commandline.
    7zip supports a variety of zip formats, including standard zip and gzip.
    Currently using VS 2015 Enterprise on Win10 Enterprise x64.

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

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