Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I suggest you consider using an HTTP Handler instead of a ASP.NET page. It will be cleaner and more performant. Just add new item of type "Generic Handler" to your project and consider moving the code to its <code>ProcessRequest</code> method. The general approach is good, though.</p> <p>By the way, unless you are explicitly mapping <code>.kml</code> files to an ASP.NET handler, it'll not run anyway. I suggest going with the default <code>.ashx</code> extension and add a <code>Content-Disposition</code> HTTP header to set the filename for the client: </p> <pre><code>Response.AddHeader("Content-Disposition", "attachment; filename=File.kml"); </code></pre> <p>Also, note that you should set header stuff <strong>before</strong> anything is sent to the client so you should move setting <code>Content-Type</code> and adding header before other stuff.</p> <hr> <p>Full Solution (From the OP):</p> <p>Here's how I did it:</p> <h3>Server</h3> <ol> <li>Add the .kml mimetype to the folder where you want this "file" to live. Say, <code>\\myDevServer\...\InetPub\KML</code><br> (<a href="http://code.google.com/apis/kml/documentation/kml_tut.html#kml_server" rel="noreferrer">Google's instructions are only for Apache</a>) <ol> <li>Open <code>Internet Information Services (IIS) Manager</code> on your DEV server</li> <li>Navigate to your DEV site</li> <li>Right-click the <code>KML</code> folder and choose <code>Properties</code></li> <li>Click the <code>HTTP Headers</code> tab</li> <li>Click the <code>MIME types</code> button</li> <li>Click <code>New</code></li> <li>Enter <ul> <li>Extension: .kml</li> <li>MIME Type: application/vnd.google-earth.kml+xml</li> </ul></li> <li>Click <code>OK</code> twice to get back to the <code>HTTP Headers</code> tab</li> </ol></li> <li>Set the <code>KML</code> folder as an ASP.NET application (maybe optional depending on how your server is set up) <ol> <li>Click the <code>Directory</code> tab</li> <li>Click the <code>Create</code> button</li> <li>The <code>Application name</code> field becomes active with the setting <code>KML</code></li> <li>Click <code>OK</code> taking you back to the main IIS Manager window</li> </ol></li> </ol> <h3>Website</h3> <ol> <li>Open VS2008: <ol> <li>File >> New Website</li> <li>Choose: <ul> <li><code>Empty Web Site</code></li> <li>Language: <code>C#</code></li> <li>Location: <code>\\myDevServer\...\InetPub\KML\</code></li> </ul></li> </ol></li> <li>In <code>Solution Explorer</code> <ol> <li>Rightclick the website</li> <li>Choose <code>New Item</code></li> <li>Choose <code>Generic Handler</code> from the <code>Visual Studio installed templates</code> window</li> <li>Enter a name (I used <code>MelroseVista.ashx</code> )</li> <li>Choose Language: <code>Visual C#</code></li> <li>Click <code>OK</code></li> </ol></li> <li>Paste the following code</li> </ol> <p>//</p> <pre><code>using System; using System.Web; using System.Xml; public class Handler : IHttpHandler { public void ProcessRequest( HttpContext context) { context.Response.ContentType = "application/vnd.google-earth.kml+xml"; context.Response.AddHeader("Content-Disposition", "attachment; filename=MelroseVista.kml"); XmlTextWriter kml = new XmlTextWriter(context.Response.OutputStream, System.Text.Encoding.UTF8); kml.Formatting = Formatting.Indented; kml.Indentation = 3; kml.WriteStartDocument(); kml.WriteStartElement("kml", "http://www.opengis.net/kml/2.2"); kml.WriteStartElement("Placemark"); kml.WriteElementString("name", "Melrose Vista FL"); kml.WriteElementString("description", "A nice little town"); kml.WriteStartElement("Point"); kml.WriteElementString("coordinates", "-80.18451400000000000000,26.08816400000000000000,0"); kml.WriteEndElement(); // &lt;Point&gt; kml.WriteEndElement(); // &lt;Placemark&gt; kml.WriteEndDocument(); // &lt;kml&gt; kml.Close(); } public bool IsReusable { get { return false; } } } </code></pre> <ol> <li>Attempt to load your page in your favorite browser</li> <li>You <em>should</em> get a popup asking you to <code>open</code> or <code>save</code> the resulting KML file.</li> <li>If you <code>open</code> it, you <em>should</em> have GoogleEarth launch itself and zoom to a thumbtack in Eastern Florida</li> <li>If you <code>save</code> it, you <em>should</em> see the following in the file</li> </ol> <p>\ </p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;kml xmlns="http://www.opengis.net/kml/2.2"&gt; &lt;Placemark&gt; &lt;name&gt;Melrose Vista FL&lt;/name&gt; &lt;description&gt;A nice little town&lt;/description&gt; &lt;Point&gt; &lt;coordinates&gt;-80.18451400000000000000,26.08816400000000000000,0&lt;/coordinates&gt; &lt;/Point&gt; &lt;/Placemark&gt; &lt;/kml&gt; </code></pre> <p>Note: <code>XmlTextWriter</code> worked pretty well here. However, I think <code>XMLDocument</code> looks more promising for larger KML files since you can manipulate it in memory before pushing it to the user. If, for example, you want the same point to appear in multiple folders in the GoogleEarth Locations tree.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload