|
-
Aug 18th, 2012, 02:38 AM
#1
Thread Starter
Frenzied Member
[RESOLVED] Zip archives
Here is my code:
Code:
Public Function extractZipArchive() As Boolean
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 Function
I am importing the following:
Code:
Imports System.IO
Imports System.IO.Compression
I am getting the following error:
Type 'ZipArchive' is not defined.
How can I fix this error?
-
Aug 18th, 2012, 03:05 AM
#2
Re: Zip archives
ZIP support in System.IO.Compression is new in .NET 4.5. If you're not using VS 2012 and targeting .NET 4.5 then that support is not available to you. ZIP support has existed since .NET 3.0 in the System.IO.Packaging namespace but it works differently. Other than that, you can use a third-party component, e.g. DotNetZip and SharpZipLib are both free.
-
Aug 18th, 2012, 10:32 AM
#3
Thread Starter
Frenzied Member
Re: Zip archives
I am using both VS 2012 and .NET 4.5
Why am I getting the 'Type 'ZipArchive' is not defined' error?
More specifically... how can I get my code working?
-
Aug 18th, 2012, 10:52 AM
#4
Re: Zip archives
Isn't 'ZipFile' the type?
-
Aug 18th, 2012, 11:02 AM
#5
Re: Zip archives
 Originally Posted by dunfiddlin
Isn't 'ZipFile' the type?
No it isn't. You'd be thinking about one or more third-party components that provide ZIP support.
Have you referenced the appropriate assembly? Presumably not. Some members of the System.IO.Compression namespace are defined in the System.dll assembly, so you can import that namespace without any issue. The ZipArchive class is not defined in that assembly though. You can open the MSDN Library and read the documentation for the class, which you should have already done. As for all types, that documentation will tell you what namespace the type is a member of and what assembly it's defined in. Hopefully doing it for yourself this time will help you remember to do it for yourself next time without being prompted.
-
Aug 18th, 2012, 11:09 AM
#6
Re: Zip archives
 Originally Posted by jmcilhinney
No it isn't. You'd be thinking about one or more third-party components that provide ZIP support.
Er no, I'd be thinking about http://visualstudiomagazine.com/arti...VBzipfig1.ashx
and the accompanying article
By comparison, the code to compress a folder and its contents with the ZIPFile class in .NET Framework 4.5 Beta is a single line using static methods of the ZIPFile class:
IO.Compression.ZIPFile.CreateFromDirectory(
FolderPath, ZipFullFilename, Optimization, includeBaseDirectory:=False)
-
Aug 18th, 2012, 11:10 AM
#7
Thread Starter
Frenzied Member
Re: Zip archives
which you should have already done
I have done this.
The page says:
Namespace: System.IO.Compression
Assembly: System.IO.Compression (in System.IO.Compression.dll)
I have imported the following:
Imports System.IO.Compression
What else do I need to do... isn't that all that needs to be done?
-
Aug 18th, 2012, 11:23 AM
#8
Re: Zip archives
 Originally Posted by dunfiddlin
Ah OK, didn't know about that one. Actually, the OP is using both. ZipFile is a static class, much like a module, so it has just Shared members. Some of those members create ZipArchive objects.
-
Aug 18th, 2012, 11:25 AM
#9
Re: Zip archives
 Originally Posted by Simon Canning
I have done this.
The page says:
I have imported the following:
What else do I need to do... isn't that all that needs to be done?
You could start by reading what I posted previously.
Have you referenced the appropriate assembly? ... that documentation will tell you ... what assembly it's defined in.
If you don't know the difference between an assembly and a namespace then I suggest that you follow the Blog link in my signature and check out my post on Assemblies & Namespaces.
-
Aug 19th, 2012, 03:11 AM
#10
Thread Starter
Frenzied Member
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
|