All the modifyed elements in KML are not saving


I am using C# Console application for KML file. how to save all the elements. I modified Placemark and Description. after saving the file its saving only Placemark value and its not saving Description value.

// Declare string to read the file name and file Path Path
        string value = ConfigurationManager.AppSettings["kMLFile"]; // calling from App.config
        string Seconds = ConfigurationManager.AppSettings["Sec"]; // calling from App.config
        int SEC = Convert.ToInt32(Seconds); //converting string to int
        decimal SECD = (decimal)SEC * 100 / 100; // converting to int to decimal

        int xy = value.LastIndexOf('\\');
        string fileName = value.Substring(xy + 1);
        string path = value.Substring(0, xy + 1);
        int dot = fileName.LastIndexOf('.');
        string name = fileName.Substring(0, dot);
        string kMLName = name + ".kML";
        string kmlfilepath = path + name + "_info.kml";

        TextReader reader = File.OpenText(value);
        KmlFile kf = KmlFile.Load(reader);
        Kml kml = kf.Root as Kml;

        if (kml != null)
            Console.WriteLine("Total number of placemarkers: " + kml.Flatten().OfType<Placemark>().Count().ToString());

            foreach (var placemark in kml.Flatten().OfType<Placemark>())
                string Oldvalue = placemark.Name;
                Console.WriteLine("Current Value: " + placemark.Name);

                try //this try block is needed to know if you can convert the name to int
                    //now try to update this placemarker values and save it
                    placemark.Name = (Convert.ToDouble(placemark.Name) - (SEC)).ToString();
                    string NewValue = Convert.ToDouble(placemark.Name).ToString();
                    string Aval = NewValue + ".0000";

                    Console.WriteLine("New Value: " + NewValue);
                    Console.WriteLine("Decimal Value: " + Aval);

                    var x = placemark.Description.Text;

                    x = x.Replace(Oldvalue, (Aval));
                    Console.WriteLine("Update Desc: " + (x));

                    // This allows us to save and Element easily. 
                    KmlFile kmlf = KmlFile.Create(placemark, false);

                    using (var file = File.Create(kmlfilepath))
                       // KmlFile Kmlf = KmlFile.Create(placemark, false);


                catch (Exception)
                    //do nothing

            Console.WriteLine("Total number of placemarkers: 0");
Closed Feb 26, 2016 at 8:49 PM by samcragg
I can't see in the sample where you're assigning to the description (you seem to be modifying a copy of the description string, but string's in .NET are immutable so it isn't a reference to the string in the description).

Can you create a simple reproducible program and post it to the discussions if you're still having a problem, thanks