<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Load, edit and save kmz file in .NET Maps SDK Questions</title>
    <link>https://community.esri.com/t5/net-maps-sdk-questions/load-edit-and-save-kmz-file/m-p/1231644#M11479</link>
    <description>&lt;P&gt;Hello all,&lt;/P&gt;&lt;P&gt;I've been working on an WinUI app in which I can load and display a kmz file as an operational layer on a mapview. But, I want also to edit and save the kmz file with the added information.&lt;/P&gt;&lt;P&gt;To load the information, I use the following:&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;kmlLayer = new KmlLayer(new Uri(@"C:\Users\markv\Downloads\Trektochtlocaties.kmz"));
MapView.Map.OperationalLayers.Add(kmlLayer);&lt;/LI-CODE&gt;&lt;P&gt;I am also able to add a placemark using:&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;try
                {
                    SketchCreationMode creationMode;
                    creationMode = SketchCreationMode.Point;
                    Geometry geometry = await MapView.SketchEditor.StartAsync(creationMode, true);
                    Geometry projectedGeometry = GeometryEngine.Project(geometry, SpatialReferences.Wgs84);
                    KmlGeometry kmlGeometry = new KmlGeometry(projectedGeometry, KmlAltitudeMode.ClampToGround);
                    currentPlacemark = new KmlPlacemark(kmlGeometry);
                    currentPlacemark.Style = new KmlStyle();
                    currentPlacemark.Style.IconStyle = new KmlIconStyle(new KmlIcon(new Uri("https://static.arcgis.com/images/Symbols/Shapes/BluePin1LargeB.png")), 1.0);
                    kmlDocument.ChildNodes.Add(currentPlacemark);
                }
                catch { }&lt;/LI-CODE&gt;&lt;P&gt;and then save a new file using the following code:&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;try
                {
                    MapView.SketchEditor.CompleteCommand.Execute(null);
                    //Remove old file
                    try { System.IO.File.Delete(@"C:\Users\markv\Downloads\Trektochtlocaties_old.kmz"); } catch { }

                    //Rename and delete current file
                    System.IO.File.Copy(@"C:\Users\markv\Downloads\Trektochtlocaties.kmz", @"C:\Users\markv\Downloads\Trektochtlocaties_old.kmz");
                    System.IO.File.Delete(@"C:\Users\markv\Downloads\Trektochtlocaties.kmz");

                    //Save new file
                    await kmlDocument.SaveAsAsync(@"C:\Users\markv\Downloads\Trektochtlocaties.kmz");
                }
                catch { }&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;So, I can load the existing file, and seperate from that add placemarks to a new kmlDocument and save that to a file. But, this causes the existing file to be overwritten with the new file, so the existing information disappears.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;How can I combine these codes in order to load a file, edit that file and save all the information? Thanks!&lt;/P&gt;</description>
    <pubDate>Tue, 15 Nov 2022 11:21:46 GMT</pubDate>
    <dc:creator>MarkvanWinkelen</dc:creator>
    <dc:date>2022-11-15T11:21:46Z</dc:date>
    <item>
      <title>Load, edit and save kmz file</title>
      <link>https://community.esri.com/t5/net-maps-sdk-questions/load-edit-and-save-kmz-file/m-p/1231644#M11479</link>
      <description>&lt;P&gt;Hello all,&lt;/P&gt;&lt;P&gt;I've been working on an WinUI app in which I can load and display a kmz file as an operational layer on a mapview. But, I want also to edit and save the kmz file with the added information.&lt;/P&gt;&lt;P&gt;To load the information, I use the following:&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;kmlLayer = new KmlLayer(new Uri(@"C:\Users\markv\Downloads\Trektochtlocaties.kmz"));
MapView.Map.OperationalLayers.Add(kmlLayer);&lt;/LI-CODE&gt;&lt;P&gt;I am also able to add a placemark using:&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;try
                {
                    SketchCreationMode creationMode;
                    creationMode = SketchCreationMode.Point;
                    Geometry geometry = await MapView.SketchEditor.StartAsync(creationMode, true);
                    Geometry projectedGeometry = GeometryEngine.Project(geometry, SpatialReferences.Wgs84);
                    KmlGeometry kmlGeometry = new KmlGeometry(projectedGeometry, KmlAltitudeMode.ClampToGround);
                    currentPlacemark = new KmlPlacemark(kmlGeometry);
                    currentPlacemark.Style = new KmlStyle();
                    currentPlacemark.Style.IconStyle = new KmlIconStyle(new KmlIcon(new Uri("https://static.arcgis.com/images/Symbols/Shapes/BluePin1LargeB.png")), 1.0);
                    kmlDocument.ChildNodes.Add(currentPlacemark);
                }
                catch { }&lt;/LI-CODE&gt;&lt;P&gt;and then save a new file using the following code:&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;try
                {
                    MapView.SketchEditor.CompleteCommand.Execute(null);
                    //Remove old file
                    try { System.IO.File.Delete(@"C:\Users\markv\Downloads\Trektochtlocaties_old.kmz"); } catch { }

                    //Rename and delete current file
                    System.IO.File.Copy(@"C:\Users\markv\Downloads\Trektochtlocaties.kmz", @"C:\Users\markv\Downloads\Trektochtlocaties_old.kmz");
                    System.IO.File.Delete(@"C:\Users\markv\Downloads\Trektochtlocaties.kmz");

                    //Save new file
                    await kmlDocument.SaveAsAsync(@"C:\Users\markv\Downloads\Trektochtlocaties.kmz");
                }
                catch { }&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;So, I can load the existing file, and seperate from that add placemarks to a new kmlDocument and save that to a file. But, this causes the existing file to be overwritten with the new file, so the existing information disappears.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;How can I combine these codes in order to load a file, edit that file and save all the information? Thanks!&lt;/P&gt;</description>
      <pubDate>Tue, 15 Nov 2022 11:21:46 GMT</pubDate>
      <guid>https://community.esri.com/t5/net-maps-sdk-questions/load-edit-and-save-kmz-file/m-p/1231644#M11479</guid>
      <dc:creator>MarkvanWinkelen</dc:creator>
      <dc:date>2022-11-15T11:21:46Z</dc:date>
    </item>
  </channel>
</rss>

