I've been trying to save an xml file to the phone for later use. I have tried to save it to Environment.SpecialFolder.MyDocuments
, Environment.SpecialFolder.Personal
, and Environment.SpecialFolder.LocalApplicationData
. All of these work in the app session, as in I can save a file and read from it as long as the app is running. As soon as I close the app and reopen it, the app is supposed to read from the file and display information, but for some reason the file either does not exist (in which case the app creates a new blank one), or it's blank. I want to try and see what the file looks like itself, but I can't even find where it's stored because I just use the Environment.SpecialFolder... path. I've so far only tested this app on android if that helps.
Any help is greatly appreciated!
Here is the code to save data to the file checkins.xml:
//make new check in
//load the document
XmlDocument checkInDoc = new XmlDocument();
checkInDoc.Load(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "checkIns.xml");
//create the nodes
XmlNode checkInNode = checkInDoc.CreateElement("CheckIn");
XmlNode nameNode = checkInDoc.CreateElement("Name");
XmlNode timeNode = checkInDoc.CreateElement("Time");
//assign values to the nodes
nameNode.InnerText = "New Check In";
timeNode.InnerText = "9:00 PM";
//place nodes in document and save
checkInNode.AppendChild(nameNode);
checkInNode.AppendChild(timeNode);
checkInDoc.DocumentElement.AppendChild(checkInNode);
checkInDoc.Save(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "checkIns.xml");
And here is the code used to load the checkins from that file to a list:
List<CheckIn> tempList = new List<CheckIn>();
//Load Checkins from file into checkInList
XmlDocument checkInDoc = new XmlDocument();
checkInDoc.Load(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "checkIns.xml");
foreach(XmlNode node in checkInDoc.SelectNodes("CheckIns/CheckIn"))
{
tempList.Add(new CheckIn() { Name = node.SelectSingleNode("Name").InnerText, Time = node.SelectSingleNode("Time").InnerText });
}