This project has moved and is read-only. For the latest updates, please go here.

Change main (root) KML after creating KMZ object

Jun 6, 2013 at 11:25 AM
Is there a way to change the root KML of a KMZ object after the KMZ has been created?

At the moment I am doing this:
  1. Create main KML
  2. Create KMZ based on main KML
  3. Add orther files to the KMZ
  4. Save KMZ to disk file
I would like to modify the main KML just before I save the KMZ to disk. Is this possible?

Thanks.
Jun 6, 2013 at 10:05 PM
It is but it's not a simple as it should be and it might not work if the KMZ archive contains more than one KML file (I'm not sure how the UpdateEntry works in the zip library - as long as it keeps the order of the table of contents the same then it will work fine with multiple KML files).

What you can do is replace the root KML file. You can call the UpdateFile method with the name of the root KML file, which will be doc.kml (see KmzFile.DefaultKmlFilename), but you'll have to save the KML to a byte array first (either save the KmlFile to a MemoryStream or use the Serializer class, as used by the CreateKml.cs example)

Hope that helps but let me know if you get stuck and I'll try to post some code.

Sam