如题。
解决方案 »
- 后台添加修改数据显示"用户代码未处理Exception,未将对象引用设置到对象的实例."
- [WinForm]如何在程序运行时对程序进行操作(以迅雷举例说)
- api调用的问题
- C# winform :datagridview如何对动态的表进行增删改?
- C#如何做属性值的传递
- 怎样调用类,创建对象?
- 弹出对话框问题!在线等
- 求教:在webform中Button_Click按钮如何能实现如下功能:
- Excel数据导入到SQL Server数据库(C#)
- MVC 拼接字段并传入easyui datagrid
- 求单源最短路径的程序或算法
- 急:.net2003如何通过visio2002逆向工程生成C#类的UML图?
{
public ClassConfigurationSettings()
{
}/// <summary>
/// 修改配置文件(数据库连接字符串)
/// </summary>
/// <param name="connString"></param>
public static void updateConfig(string p_strKey, string p_strValue)
{
try
{
string m_strFullPath = "";
Assembly Asm = Assembly.GetExecutingAssembly();
XmlDocument xmlDoc =new XmlDocument();
m_strFullPath = Asm.Location.Substring(0, (Asm.Location.LastIndexOf("\\") + 1) ) + "YouApplication.exe.config";
xmlDoc.Load(m_strFullPath);
XmlNodeList nodeList=xmlDoc.selectSingleNode("/configuration/appSettings").ChildNodes;
foreach(XmlNode xn in nodeList)//遍历所有子节点
{
XmlElement xe=(XmlElement)xn;if( xe.GetAttribute("key").IndexOf(p_strKey) != -1 )
{
xe.SetAttribute("value",p_strValue);
}
}
xmlDoc.Save(m_strFullPath);
}
catch(System.NullReferenceException NullEx)
{
throw NullEx;
}
catch(Exception ex)
{
throw ex;
}
}}
NameValueCollection configData = (NameValueCollection)ConfigurationSettings.GetConfig(configPath);
string dtdpath = configData["dtdfilepath"]configPath 是你在config中定义的节点的path
dtdfilepath 是节点的key
dtdpath 是得到的节点value
这种方法只适合keyvalue得配置形式具体的可以参照msdn
其中Scope为Application的默认为只读,Scope为User的可以读写。
比如setting中有"LoginName"段Scope为User你可以直接读出,也可将他重新赋值,但对Scope为User的赋值不会存储到Xml配置文件中,而是存在你的“C:\Documents and Settings\Administrator\Application Data\yourapp”下,和登录用户有关。
private yourApp.Properties.Settings setting = new yourApp.Properties.Settings();
private void ReadDefault()
{
txtLoginName.Text = setting.LoginName;
}
private void WriteDefault()
{
//赋值存在“C:\Documents and Settings\Administrator\Application Data\yourapp”下
setting.LoginName = txtLoginName.Text;
}