How to use .NET configuration files (app.config, settings.settings) to save and restore all application data?

后端 未结 5 1219
灰色年华
灰色年华 2020-12-15 12:24

Although there are a lot of posts about .net config files, I believe that my requirements do not allow for any of the solutions proposed (or I don\'t understand the process

5条回答
  •  执笔经年
    2020-12-15 13:18

    Since you app.config file is a simple xml file you can load it into an XDocument:

    string path = AppDomain.CurrentDomain.SetupInformation.ConfigurationFile;
    XDocument doc = XDocument.Load(path);
    //Do your modifications to section x
    doc.Save(path);
    ConfigurationManager.RefreshSection("x");
    

    I corrected the XDocument.Load() code according to @Pat's comment

提交回复
热议问题