using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Xml;
using System.Collections;
using System.Reflection;
namespace XyPDA
{
public class gpsXMLSettingReader
{
private static Hashtable m_hsTable = null;
private static gpsXMLSettingReader sysSettingReader = null;
private gpsXMLSettingReader()
{
try
{
this.DoXMLReader();
}
catch (Exception exception)
{
throw exception;
}
}
private void DoXMLReader()
{
//this.ReadConfigData();
}
private static string GetConfigXMLFile()
{
//string strPath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().GetName().CodeBase.ToString()) + “\U8Setting.xml”;
//string strPath = @”U8Setting.xml”;
//string strPath = Path.Combine(“D:\OtherSecondaryDevelopment\Xy003\XyPDA\XyPDA\bin\Debug\U8.xml”, “”);
string strPath = @”U8.xml”;
return strPath;
}
public static gpsXMLSettingReader getInstance()
{
try
{
if (sysSettingReader == null)
{
m_hsTable = new Hashtable();
sysSettingReader = new gpsXMLSettingReader();
}
}
catch (Exception exception)
{
throw exception;
}
return sysSettingReader;
}
public static string GetSettingConfig(string pro, string par)
{
string str = “”;
//string configXMLFile = GetConfigXMLFile();
//XmlTextReader reader = new XmlTextReader(configXMLFile);
//reader.MoveToContent();
//XmlDocument document = new XmlDocument();
//document.LoadXml(reader.ReadOuterXml());
string configXMLFile = GetConfigXMLFile();
XmlDocument document = new XmlDocument();
XmlReaderSettings settings = new XmlReaderSettings();
settings.IgnoreComments = true;
XmlReader reader = XmlReader.Create(configXMLFile, settings);
document.Load(reader);
try
{
str = document.FirstChild.SelectSingleNode(pro).SelectSingleNode(par).InnerText;
reader.Close();
}
catch (Exception exception)
{
throw exception;
}
return str;
}
public static void SetSettingConfig(string pro, string par, string val)
{
string configXMLFile = GetConfigXMLFile();
XmlTextReader reader = new XmlTextReader(configXMLFile);
reader.MoveToContent();
XmlDocument document = new XmlDocument();
document.LoadXml(reader.ReadOuterXml());
try
{
XmlNode node = document.FirstChild.SelectSingleNode(pro).SelectSingleNode(par);
if (node != null)
{
node.InnerText = val;
}
reader.Close();
document.Save(configXMLFile);
}
catch (Exception exception)
{
throw exception;
}
}
}
}
调用代码如下:
this.textBox1.Text = gpsXMLSettingReader.GetSettingConfig(“config”, “ServerIP”); //读取服务器
this.textBox2.Text = gpsXMLSettingReader.GetSettingConfig(“config”, “UserID”); //读取用户名
出现问题图片如下[C# 开发PDA程序,在调试状态下提示找不到***.xml文件,但是生成EXE是没有任何问题是什么原因呀?]
2
2
46
winform程序是生成在bin对应目录下的,对于xml这种东西默认是不复制的