private void Form1_FormClosing(object sender, FormClosingEventArgs e) //Save On Form Closing
{
XmlDocument xDoc = new XmlDocument();
xDoc.Load(path + "\\Address Book - Me \\settings.xml");
XmlNode xNode = xDoc.SelectSingleNode("People");
xNode.RemoveAll();
foreach (Person pe in people)
{
XmlNode xTop = xDoc.CreateElement("People");
XmlNode xName = xDoc.CreateElement("Name");
XmlNode xLastName = xDoc.CreateElement("LastName");
XmlNode xStreet = xDoc.CreateElement("Address");
XmlNode xPhone = xDoc.CreateElement("Phone");
XmlNode xEmail = xDoc.CreateElement("Email");
XmlNode xDate = xDoc.CreateElement("Birth");
XmlNode xCity = xDoc.CreateElement("City");
XmlNode xState = xDoc.CreateElement("State");
XmlNode xCountry = xDoc.CreateElement("Country");
XmlNode xDetails = xDoc.CreateElement("Detail");
xName.InnerText = pe.Name;
xLastName.InnerText = pe.LastName;
xStreet.InnerText = pe.StreetAdress;
xPhone.InnerText = pe.Phone;
xEmail.InnerText = pe.Email;
xDate.InnerText = pe.Date.ToFileTime().ToString();
xCity.InnerText = pe.City;
xState.InnerText = pe.State;
xCountry.InnerText = pe.Country;
xDetails.InnerText = pe.Details;
xTop.AppendChild(xName);//adding a new node
xTop.AppendChild(xLastName);
xTop.AppendChild(xStreet);
xTop.AppendChild(xPhone);
xTop.AppendChild(xEmail);
xTop.AppendChild(xDate);
xTop.AppendChild(xCity);
xTop.AppendChild(xState);
xTop.AppendChild(xCountry);
xTop.AppendChild(xDetails);
xDoc.DocumentElement.AppendChild(xTop);
}
xDoc.Save(path + "\\Address Book - Me \\settings.xml");//
Я пытаюсь создать агент, который сохраняет информацию и перезагружает ее после перезапуска приложения. Но когда я закрыл свою программу, ничего не работает, и все:
Xml Произошло необработанное исключение типа «System.Xml.XmlException» в System.Xml.dll и Дополнительная информация: Отсутствует корневой элемент.
Помогите мне, пожалуйста.
Из комментария: здесь было выброшено исключение: xDoc.Load(path + "\\Address Book - Me \\settings.xml");