This project is read-only.

Opening a KMZ file

Jul 24, 2009 at 2:15 PM

I am trying to open a KMZ file within a C# application in order to access the files within the archive.  The library does not recognize this as a zip file, even though the documentation that I've found on *.kmz files states that they of the ZIP format.  Is there a way I can get DotNetZip to open these type of files?

Jul 24, 2009 at 3:24 PM
Edited Jul 24, 2009 at 3:54 PM

"The library does not recognize this as a zip file"

What's the error you get?

I don't know what a KMZ file is.  if you could make it available to me, I'd be happy to look at it.



Jul 24, 2009 at 3:58 PM

A KMZ file is a compressed archive of Google Earth data files.  Typically the file extension is *.kmz.

I just found a nugget on this page that recommends to simplly change the file extension from *.kmz to *.zip and I should be able to manipulate it. I just tested this in my app and, once I change the extension, I don't have any problems.

Jul 24, 2009 at 4:10 PM

The library doesn't care about the name of the file ??

Jul 24, 2009 at 4:19 PM

I'm not sure I was entirely clear in my second post.

Originally, I used a line in my code like this

ZipFile zf = new ZipFile(@"Data\MyPlaces.kmz");
<font size="2">

After I read the link that I referenced above, I made a copy of MyPlaces.kmz and renamed the copy to "".  Then in my code I switched the line to



ZipFile zf = new ZipFile(@"Data\");

and I was able to access the contents of the file.

I'm not sure why Google felt the need to create a new extension for a common file compression format.  It seems to indicate that I have do a file copy and rename before I unzip the file in my program.

Jul 24, 2009 at 4:47 PM

Ah, I see.

To avoid the rename, you can use the ZipFile.Read() method, instead of the constructor.

  ZipFile zf = ZipFile.Read(@"Data\MyPlaces.kmz");

Of course you should wrap that in a using clause:

  using (ZipFile zf = ZipFile.Read(@"Data\MyPlaces.kmz")) 
Jul 24, 2009 at 4:56 PM

Oh, cool...  That really helps (and sure saves on having to rename).


Oct 5, 2010 at 6:38 PM

there are good reasons (document management) why these files are given an extension different to ZIP.

There are many zip files formats that are directly opened by their respective applications: docx / xlsx / pptx in MS Office...