为什么用OpenFileDialog读取的路径无法写入xml文件,请问要怎么写,才能把路径写入INI文件呢? 请高手帮忙,
我写的代码: 先用OpenFileDialog读取的路径,然后显示在TextBox1上,然后保存TextBox1上文件(点击Button2写入ini文件) 不通过OpenFileDialog,直接TextBox1写路径可保存入xml文件,经过读取OpenFileDialog路径就无法写入xml文件了
OpenFileDialog openFileDialogScl = new OpenFileDialog();
openFileDialogScl.FileName = "*.mdb";
openFileDialogScl.Filter = "mdb files (*.mdb)|*.mdb|All files (*.*)|*.*";
openFileDialogScl.ShowDialog();
if (openFileDialogScl.ShowDialog() == DialogResult.OK)
{
string strPath = System.IO.Path.GetDirectoryName(openFileDialogScl.FileName.ToString()).ToString().Trim();
textSCLStation.Text = strPath;
}
其中 stripaddress 就是 textSCLStation
private void WriteXmlMachine(string fileName,string strIpAddress, string strUser, string strPass, string strHour, string strMin,string strClass,string strDataPass,string strUp,string strRe)
{
try
{
XmlTextWriter xmlwriter = new XmlTextWriter(fileName,System.Text.Encoding.UTF32);//,System.Text.Encoding.UTF8
xmlwriter.Formatting = Formatting.Indented;
xmlwriter.WriteStartElement("Set");
xmlwriter.WriteComment("设备设置信息");
xmlwriter.WriteElementString("Station", strIpAddress);
xmlwriter.WriteElementString("User", strUser);
xmlwriter.WriteElementString("Pass", strPass);
xmlwriter.WriteElementString("Hour", strHour);
xmlwriter.WriteElementString("Min", strMin);
xmlwriter.WriteElementString("Class", strClass);
xmlwriter.WriteElementString("DataPass", strDataPass);
xmlwriter.WriteElementString("Up", strUp);
xmlwriter.WriteElementString("Re", strRe);
xmlwriter.WriteEndElement();
xmlwriter.Close();
}
catch (Exception ex)
{
return;
}
}
我写的代码: 先用OpenFileDialog读取的路径,然后显示在TextBox1上,然后保存TextBox1上文件(点击Button2写入ini文件) 不通过OpenFileDialog,直接TextBox1写路径可保存入xml文件,经过读取OpenFileDialog路径就无法写入xml文件了
OpenFileDialog openFileDialogScl = new OpenFileDialog();
openFileDialogScl.FileName = "*.mdb";
openFileDialogScl.Filter = "mdb files (*.mdb)|*.mdb|All files (*.*)|*.*";
openFileDialogScl.ShowDialog();
if (openFileDialogScl.ShowDialog() == DialogResult.OK)
{
string strPath = System.IO.Path.GetDirectoryName(openFileDialogScl.FileName.ToString()).ToString().Trim();
textSCLStation.Text = strPath;
}
其中 stripaddress 就是 textSCLStation
private void WriteXmlMachine(string fileName,string strIpAddress, string strUser, string strPass, string strHour, string strMin,string strClass,string strDataPass,string strUp,string strRe)
{
try
{
XmlTextWriter xmlwriter = new XmlTextWriter(fileName,System.Text.Encoding.UTF32);//,System.Text.Encoding.UTF8
xmlwriter.Formatting = Formatting.Indented;
xmlwriter.WriteStartElement("Set");
xmlwriter.WriteComment("设备设置信息");
xmlwriter.WriteElementString("Station", strIpAddress);
xmlwriter.WriteElementString("User", strUser);
xmlwriter.WriteElementString("Pass", strPass);
xmlwriter.WriteElementString("Hour", strHour);
xmlwriter.WriteElementString("Min", strMin);
xmlwriter.WriteElementString("Class", strClass);
xmlwriter.WriteElementString("DataPass", strDataPass);
xmlwriter.WriteElementString("Up", strUp);
xmlwriter.WriteElementString("Re", strRe);
xmlwriter.WriteEndElement();
xmlwriter.Close();
}
catch (Exception ex)
{
return;
}
}
textSCLStation.Text 值