title: How to write a kml file to publicly accessible server?
body: <p>I want to render a KML file in google maps from my asp.net MVC 3 app.</p>
  
  <p>From Google Maps JavaScript API V3, I'm using KmlLayer('url') to render the kml in google maps.
  I have read that kml file needs to be in a publicly accessible server. I could render the kml file locally with third party javascripts but they can be prone to errors. 
  (<a href="https://stackoverflow.com/questions/3514785/loading-a-local-kml-file-using-google-maps">Loading a local .kml file using google maps?</a>)</p>
  
  <p>The kml files I want to render are stored in a SQL server database as byte arrays. So for one Kml file I have to write the byte array into a path with kml extension. I have done this with File.WriteAllBytes(path, byte), where path = local path and byte = byte array from Database. THis is done in the Controller of MVC app.
  This is the code:</p>
  
  <pre><code>public ActionResult MapView(int id)
          {
            Incident inc = db.Incidents.Find(id);
              if (inc.IncidentDatas.Count != 0)
              {
                  ViewBag.ListKmlUrls = kmlFileStore(inc);
              }
  
              return View(inc);
          }
  
  public List&lt;string&gt; kmlFileStore(Incident inc)
          {
              List&lt;string&gt; listKmlUrls = new List&lt;string&gt;();
              // Specify a "currently active folder"
              string activeDir = @"c:\incident" + inc.incId + @"\incidentData";
  
              //Create a new subfolder under the current active folder
              string newPath = System.IO.Path.Combine(activeDir, "kmlFiles");
  
              // Create the subfolder
              System.IO.Directory.CreateDirectory(newPath);
  
              String url;
              foreach(var d in inc.IncidentDatas) {
                  url = @"c:\incident" + inc.incId + @"\incidentData\kmlFiles\" + d.id + ".kml";
  
                   //dataContent is byte[]
                  System.IO.File.WriteAllBytes(url, d.dataContent);
                  listKmlUrls.Add(url);
              }
  
              return listKmlUrls;
          }
  </code></pre>
  
  <p>The idea is the view will access the list of urls through viewbag to pass urls to javascript method KmlLayer(...). But the urls here are only local paths.</p>
  
  <p>So how can the MVC app store the kml file to a publicly accessible server so that it can pass a url to KmlLayer(...)? This would have to be done programmatically.</p>
  
  <p>I'm currently accessing my MVC app and database from localhost. I have a static Ip and name. I would also like to publish the app and database for online access. Not sure how to proceed, please give me some advice/guidance. Thanks.</p>