如题。

解决方案 »

  1.   

    public class ClassConfigurationSettings
    {
    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;
    }
    }}
      

  2.   

    string configPath = "news/bizlogic/news/filepath";
    NameValueCollection configData = (NameValueCollection)ConfigurationSettings.GetConfig(configPath);
    string dtdpath = configData["dtdfilepath"]configPath 是你在config中定义的节点的path
    dtdfilepath 是节点的key
    dtdpath 是得到的节点value
    这种方法只适合keyvalue得配置形式具体的可以参照msdn
      

  3.   

    System.Configuration.ConfigurationSettings.AppSettings["ConnStrin"]
      

  4.   

    .net已经映射过了,可以当对象访问。要看他怎么映射的可以看他映射类的源码,你可以直接使用Settings类。
    其中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;
     }