Results 1 to 8 of 8

Thread: DotNetZip UnZip/Zip with file locations

  1. #1

    Thread Starter
    Addicted Member HunterTTP's Avatar
    Join Date
    Jul 2012
    Posts
    146

    Question DotNetZip UnZip/Zip with file locations

    I've got the problem narrowed down, I just don't know how to fix it.

    Here is an example code-

    Variables for example:
    Code:
    Dim Username As String = Environment.UserName
        Dim AppData As String = "C:\Users\" & Username & "\AppData\Roaming"
    Zip and UnZip subs:
    Code:
    Public Sub MyZip(ByVal ContentFolder As String, ByVal CreateZip As String)
            Using zip As ZipFile = New ZipFile()
                zip.AddDirectory(ContentFolder)
                zip.Save(CreateZip)
            End Using
        End Sub
    Code:
    Public Sub MyExtract(ByVal ZipToUnpack As String, ByVal UnpackDirectory As String)
            Using zip As ZipFile = ZipFile.Read(ZipToUnpack)
                Dim e As ZipEntry
                For Each e In zip
                    e.Extract(UnpackDirectory, ExtractExistingFileAction.OverwriteSilently)
                Next
            End Using
        End Sub
    How I call the subs:
    Code:
    MyExtract(AppData & "\test.zip", AppData & "\testdirectory")
    
    MyZip(AppData & "\testdirectory", AppData & "\test.zip")
    All this works fine, but the problem is that DotNetZip will not take file locations in this form. I get this weird "FileStream will not open Win32 devices such as disk partitions and tape drives. Avoid use of "\\.\" in the path." error. If I just put the zip and folder names (instead of locations + names) it works fine but only looks in it's local directory. How do I get it to function as I need it to?
    Last edited by HunterTTP; Nov 22nd, 2012 at 09:31 AM.

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

    Re: DotNetZip UnZip/Zip with file locations

    I would guess that what's happening is that each entry in the archive has a full path attribute and by then trying to extract the entry to a specific folder you are ending up with an invalid path like "C:\SomeFolder\C:\SomeFolder\SomeFile.ext". I've never used DotNetZip so I don't know if that's the case or how you'd fix it but maybe see if there's an Extract overload that doesn't take a location and just uses the path contained in the entry or else ignores the path in the entry and uses the path you specify.

  3. #3

    Thread Starter
    Addicted Member HunterTTP's Avatar
    Join Date
    Jul 2012
    Posts
    146

    Re: DotNetZip UnZip/Zip with file locations

    I've googled for hours. If you guys can find a fix, I would gladly accept it. <3

  4. #4

    Thread Starter
    Addicted Member HunterTTP's Avatar
    Join Date
    Jul 2012
    Posts
    146

    Re: DotNetZip UnZip/Zip with file locations

    I've been to countless websites looking for this. Every example just uses "example.zip" and never tries to "save" it anywhere else. eg C:\Windows\example.zip. When I finally find some kind of solution, it is in C#. I can't believe this is this hard to find when the entire purpose of DotNetZip is to easily zip and unzip files within .Net applications. u_U

  5. #5

    Thread Starter
    Addicted Member HunterTTP's Avatar
    Join Date
    Jul 2012
    Posts
    146

    Re: DotNetZip UnZip/Zip with file locations

    Quote Originally Posted by jmcilhinney View Post
    I would guess that what's happening is that each entry in the archive has a full path attribute and by then trying to extract the entry to a specific folder you are ending up with an invalid path like "C:\SomeFolder\C:\SomeFolder\SomeFile.ext". I've never used DotNetZip so I don't know if that's the case or how you'd fix it but maybe see if there's an Extract overload that doesn't take a location and just uses the path contained in the entry or else ignores the path in the entry and uses the path you specify.
    Do you think that it means the periods in a string when it says "Avoid use of "\\.\" in the path."

  6. #6
    PowerPoster dunfiddlin's Avatar
    Join Date
    Jun 2012
    Posts
    8,245

    Re: DotNetZip UnZip/Zip with file locations

    Um ... the code that you have above ...

    vb.net Code:
    1. Imports Ionic.Zip
    2.  
    3. Public Class Form1
    4.     Dim Username As String = Environment.UserName
    5.     Dim AppData As String = "C:\Users\" & Username & "\AppData\Roaming"
    6.  
    7.     Public Sub MyZip(ByVal ContentFolder As String, ByVal CreateZip As String)
    8.         Using zip As ZipFile = New ZipFile()
    9.             zip.AddDirectory(ContentFolder)
    10.             zip.Save(CreateZip)
    11.         End Using
    12.     End Sub
    13.  
    14.     Public Sub MyExtract(ByVal ZipToUnpack As String, ByVal UnpackDirectory As String)
    15.         Using zip As ZipFile = ZipFile.Read(ZipToUnpack)
    16.             Dim e As ZipEntry
    17.             For Each e In zip
    18.                 e.Extract(UnpackDirectory, ExtractExistingFileAction.OverwriteSilently)
    19.             Next
    20.         End Using
    21.     End Sub
    22.  
    23.  
    24.     Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    25.         MyExtract(AppData & "\test.zip", AppData & "\testdirectory")
    26.  
    27.         MyZip(AppData & "\testdirectory", AppData & "\test.zip")
    28.     End Sub
    29. End Class

    runs without error and with total success in both VS Express 2012 & VB.Net 2010 (once you've actually done a zip - your ordering of the calls is a little odd so I did my first run with the extract call commented out). You're not finding a fix cos there's nothing to fix, I'm afraid. Wherever the problem is coming from it's not this.
    As the 6-dimensional mathematics professor said to the brain surgeon, "It ain't Rocket Science!"

    Reviews: "dunfiddlin likes his DataTables" - jmcilhinney

    Please be aware that whilst I will read private messages (one day!) I am unlikely to reply to anything that does not contain offers of cash, fame or marriage!

  7. #7

    Thread Starter
    Addicted Member HunterTTP's Avatar
    Join Date
    Jul 2012
    Posts
    146

    Re: DotNetZip UnZip/Zip with file locations

    Well that is better than nothing. I guess my MyExtract and MyZip work well. I wonder what could be the problem? I'm reinstalling VB2012 now. When I download the DotNetZip.zip I just need the Ionic.Zip.dll correct? Then I add a reference to it, and "Imports Ionic.Zip" to the very top.

  8. #8
    PowerPoster dunfiddlin's Avatar
    Join Date
    Jun 2012
    Posts
    8,245

    Re: DotNetZip UnZip/Zip with file locations

    Yup!
    As the 6-dimensional mathematics professor said to the brain surgeon, "It ain't Rocket Science!"

    Reviews: "dunfiddlin likes his DataTables" - jmcilhinney

    Please be aware that whilst I will read private messages (one day!) I am unlikely to reply to anything that does not contain offers of cash, fame or marriage!

Tags for this Thread

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