向高手请教C#中OpenFilDialog与写XML文件之间的问题!~!
我用两个按钮 button3是用来选择文件的,button5是用来写XML文件的;可是当我选择完文件后,写XML的那个按钮就写不出来XML文件了!不点button3就可以写XML文件!
请高手指教!!急的我头都痛了!~!!
//以下是两个按钮的代码!!
private void button3_Click(object sender, EventArgs e)
{
OpenFileDialog lcw = new OpenFileDialog();
lcw.Title = "打开文件";
lcw.Filter = "数据库备份文件(*.mdf)|*.mdf|所有文件(*.*)|*.*";
if (lcw.ShowDialog() == DialogResult.OK)
{
textBox4.Text = lcw.FileName;
/*button4.Enabled = true;
Program.dbpath = textBox4.Text;
int slenght = Program.dbpath.Length;
Program.logpath = Program.dbpath.Substring(0, slenght - 4);
Program.logpath = Program.logpath + "_log.ldf";*/
}
}
private void button5_Click(object sender, EventArgs e)
{
XmlDocument xmldoc;
XmlNode xmlnode;
XmlElement xmlelem;
XmlElement xmlelem5;
XmlElement xmlelem6;
XmlText xmltext;
string address = textBox1.Text;
string username = textBox2.Text;
string password = textBox3.Text;
IDictionary<string, string> source = new Dictionary<string, string>();
source.Add("IP", "address");
source.Add("dataname", "FC_Manage");
source.Add("uid", "username");
source.Add("password", "password");
xmldoc = new XmlDocument();
//加入XML的声明段落
xmlnode = xmldoc.CreateNode(XmlNodeType.XmlDeclaration, "", "");
xmldoc.AppendChild(xmlnode);
//加入一个根元素
xmlelem5 = xmldoc.CreateElement("", "books", "");
xmldoc.AppendChild(xmlelem5);
//加入另外一个元素
xmlelem6 = xmldoc.CreateElement("", "book", "");
xmltext = xmldoc.CreateTextNode("The text of the sample element");
xmlelem6.AppendChild(xmltext);
xmldoc.ChildNodes.Item(1).AppendChild(xmlelem6);
foreach (KeyValuePair<string, string> c in source)
{
int i=0;
xmlelem = xmldoc.CreateElement(c.Key);
xmltext=xmldoc.CreateTextNode(c.Value);
xmlelem.AppendChild(xmltext);
xmldoc.ChildNodes.Item(1).AppendChild(xmlelem);
i++;
}
//保存创建好的XML文档
try
{
xmldoc.Save("data.xml");
}
catch (Exception g)
{
//显示错误信息
Console.WriteLine(g.Message);
}
Console.ReadLine();
--------------------编程问答-------------------- 高手在哪里呀,急等解决呀!~!~ --------------------编程问答-------------------- button3_Click没看看XML操作
单步跟踪检查是否在使用
补充:.NET技术 , C#