I currently using an WPF app. Right now, i want to save my data into the XML file. If the xml file is not found in the project, then create a new one. Does anyone can teach me how?
i think the code will be something like this
public MainWindow()
{
InitializeComponent();
loadXML();
}
public void loadXML()
{
xDocument doc = xDocument.load("MyXmlFile.xml");
if(doc.exist== false)
{
//create new xml
}
}
The simplest thing do to in this instance is to use File.Exists to check if the file actually exists on disk. If it doesn’t, then we can save it, otherwise we load it: