How to save a flight plan to a file

C# using the SDK
I can load the default MSFS FlightPlan with this code …

  1. HOW DO I SAVE IT TO A FILE? a complex object?

  2. WHY is this not updated to match the real flight plan.
    this flight plan is always weird and not one that I can use.


public FlightPlan23 LoadFlightPlan23(string filePath)
{
var doc = XDocument.Load(filePath);
var flightPlanElement = doc.Element(“SimBase.Document”).Element(“FlightPlan.FlightPlan”);


var flightPlan = new FlightPlan23
{
Title = GetElementValue(flightPlanElement, "Title"),
FPType = GetElementValue(flightPlanElement, "FPType"),
RouteType = GetElementValue(flightPlanElement, "RouteType"),
CruisingAlt = double.Parse(GetElementValue(flightPlanElement, "CruisingAlt")),
DepartureID = GetElementValue(flightPlanElement, "DepartureID"),
DepartureLLA = GetElementValue(flightPlanElement, "DepartureLLA"),
DestinationID = GetElementValue(flightPlanElement, "DestinationID"),
DestinationLLA = GetElementValue(flightPlanElement, "DestinationLLA"),
Descr = GetElementValue(flightPlanElement, "Descr"),
DeparturePosition = GetElementValue(flightPlanElement, "DeparturePosition"),
DepartureName = GetElementValue(flightPlanElement, "DepartureName"),
DestinationName = GetElementValue(flightPlanElement, "DestinationName"),
ATCWaypoints = flightPlanElement.Elements("ATCWaypoint").Select(e => new ATCWaypoint23
{
ID = e.Attribute("id").Value,
ATCWaypointType = GetElementValue(e, "ATCWaypointType"),
WorldPosition = GetElementValue(e, "WorldPosition"),
SpeedMaxFP = double.Parse(GetElementValue(e, "SpeedMaxFP")),
ICAOIdent = GetElementValue(e, "ICAO.ICAOIdent")
}).ToList()
};
return flightPlan;

}

the class is this

public class FlightPlan23
{
public string Title { get; set; }
public string FPType { get; set; }
public string RouteType { get; set; }
public double CruisingAlt { get; set; }
public string DepartureID { get; set; }
public string DepartureLLA { get; set; }
public string DestinationID { get; set; }
public string DestinationLLA { get; set; }
public string Descr { get; set; }
public string DeparturePosition { get; set; }
public string DepartureName { get; set; }
public string DestinationName { get; set; }
public List ATCWaypoints { get; set; }
public FlightPlan23()
{


}

}

something starting with (i suspect)

doc.Save

thanks

IF I can solve this , my AI Flight Assistant will be ready for beta!

I have a number of small issues … some data requests work correctly as expected 9/10 times , but then a flight repeated many times will suddently receive no data and then I’m in a bind because I need to know the distance to the Runway etc. for the AI to function.