首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > C# >

xml不能保留 和 文本不能写入

2013-01-28 
xml不能保存 和文本不能写入private void Form1_FormClosing(object sender, FormClosingEventArgs e){cre

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里就能用。为什么?

热点排行