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

Output Kml instance into KMZ stream

Feb 27, 2012 at 9:41 AM

Hi

Is it possible to out a Kml instance to a KMZ stream for use in a web app. Specifically, I am thinking of generating a KML file in memory and outputing as ContentResult for an MVC app. I can see that I can serialize the Kml instance into a string. The problem is how one gets from a string stream into a KMZfile instance. Any suggestions?

Thanks

Blair

Feb 27, 2012 at 10:38 AM

Actually I think Serializer is a bit of a red herring. I am using the following though need to test further.

var stream = new MemoryStream();
var kmlFile = KmlFile.Create(kml, false);
var kmzFile = KmzFile.Create(kmlFile);
kmzFile.Save(stream);

Feb 27, 2012 at 2:14 PM
Edited Feb 27, 2012 at 2:15 PM

As you've figured out, the code snippet you've posted is probably the best way to save a Kml element to a Kmz archive. Please note that KmzFile implements IDisposable, so you probably want to wrap it in a using block.

I'll try and update the documentation to give an example but will probably look the same as your code (looking at the examples there is one for Kmz but I think there's an error with it so will get that updated as well).