Code for zip a file-VBForums
Results 1 to 4 of 4

Thread: Code for zip a file

Hybrid View

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Apr 2010
    Posts
    437

    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
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    98,265

    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.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

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

    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


    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

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

    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.

Posting Permissions

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



Featured


Click Here to Expand Forum to Full Width