public bool Save()
 {
     // ---------------------------------------------------------
     // Save the contents of this apsim document to the specified
     // file - formatted nicely.
     // ---------------------------------------------------------
     if (!ReadOnly && RootComponent != null && FileName != "Untitled")
     {
         if (BeforeSave != null)
         {
             BeforeSave.Invoke();
         }
         XmlDocument doc      = new XmlDocument();
         XmlNode     RootNode = doc.AppendChild(doc.CreateElement(RootComponent.Type));
         XmlHelper.SetAttribute(RootNode, "version", APSIMChangeTool.CurrentVersion.ToString());
         XmlHelper.SetAttribute(RootNode, "creator", "Apsim " + Configuration.Instance.ApsimVersion() + "-" + Configuration.Instance.ApsimBuildNumber());
         RootComponent.Write(RootNode);
         try { doc.Save(FileName); } //Win 7 - do not allow saving to Program Files directory
         catch (Exception e)
         {
             if (!FileName.Contains("UserInterface")) //do not try to save files in UserInterface directory as it's write protected in the default install (old versions of APSIM toolboxes will try to do this).
             {
                 System.Windows.Forms.MessageBox.Show("Error: " + e.Message + " Try saving in a different location.");
             }
             return(false);
         }
         Dirty = true;
         SetDirty(false);
         return(true);
     }
     return(false);
 }