-
Nov 22nd, 2012, 12:02 AM
#1
Thread Starter
Addicted Member
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.
-
Nov 22nd, 2012, 12:20 AM
#2
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.
-
Nov 22nd, 2012, 01:07 AM
#3
Thread Starter
Addicted Member
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
-
Nov 22nd, 2012, 09:30 AM
#4
Thread Starter
Addicted Member
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
-
Nov 22nd, 2012, 10:23 AM
#5
Thread Starter
Addicted Member
Re: DotNetZip UnZip/Zip with file locations
Originally Posted by jmcilhinney
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."
-
Nov 22nd, 2012, 11:35 AM
#6
Re: DotNetZip UnZip/Zip with file locations
Um ... the code that you have above ...
vb.net Code:
Imports Ionic.Zip
Public Class Form1
Dim Username As String = Environment.UserName
Dim AppData As String = "C:\Users\" & Username & "\AppData\Roaming"
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
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
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
MyExtract(AppData & "\test.zip", AppData & "\testdirectory")
MyZip(AppData & "\testdirectory", AppData & "\test.zip")
End Sub
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!
-
Nov 22nd, 2012, 05:47 PM
#7
Thread Starter
Addicted Member
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.
-
Nov 22nd, 2012, 06:28 PM
#8
Re: DotNetZip UnZip/Zip with file locations
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|