xml不能保存 和 文本不能写入
private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
createXml();
StreamWriter sw = new StreamWriter("only.txt");
sw.Write("0");
sw.Close();
}
private void createXml()
{
XmlDocument xmlDoc = new XmlDocument();
XmlElement xe = xmlDoc.CreateElement("titles");
string name;
for(int index=0;index <this.listView1.Items.Count;index++)
{
name = this.listView1.Items[index].Text;
XmlElement xe1 = xmlDoc.CreateElement("title");
xe1.SetAttribute("name",name);
xe1.SetAttribute("path", pathList[name]);
xe.AppendChild(xe1);
}
xmlDoc.AppendChild(xe);
xmlDoc.Save("title.xml");
}
以前代码是没问题的,今天就突然出现了xml没保存,文本不能写入数据。 把closing事件的内容放到load事件或者放到Program.cs里就能用。为什么?