winform app.config添加自定义节点

在app.config中
userSetting是自己定义的
还要在文件的头部加上configuration这一段


  
    
      

 

在代码中引用

string congfigFile = Application.ExecutablePath + ".config";
                    XmlDocument document = new XmlDocument();
                    document.Load(congfigFile);
                    XmlNodeList nodes = document.SelectNodes("/configuration/userSettings/Book.UI.Properties.Settings/setting");
                    foreach (XmlNode item in nodes)
                    {
                        switch (item.Attributes["name"].Value)
                        {
                            case "userName":
                                item.FirstChild.InnerText = this.txtUserName.Text.Trim();
                                break;
                            default:
                                break;
                        }
                        document.Save(congfigFile);
                    }


可以保存数据到配置文件中

你可能感兴趣的:(winform,app.config)