在运行时将新配置添加到App.config

时间:2020-06-20 16:06:45

标签: c# xml configuration app-config

我有一个文件(MyFile.dll.config),它是XML代码。我想在运行时将该文件的节点添加到当前的App.config中。我想读取XML文件,然后检查节点是否存在,如果不存在,则添加它们并刷新configuration node in App.config以能够使用新配置。 我要添加它们的文件中的可用节点是(basicHttpBindingendpoints

我编写了以下代码,但我不知道如何完成它。

        Configuration AppDllConfig = ConfigurationManager.OpenExeConfiguration(this.GetType().Assembly.Location);
        AppSettingsSection myDllConfigAppSettings = (AppSettingsSection)AppDllConfig.GetSection("client");

        XmlDocument xmlDoc = new XmlDocument();
        xmlDoc.Load(MyFilePath);
        XmlNodeList xmlnodes = xmlDoc.SelectNodes("/configuration/client/endpoint");


        AppDllConfig.Save(ConfigurationSaveMode.Modified);
        ConfigurationManager.RefreshSection("configuration");

感谢任何帮助。

0 个答案:

没有答案
相关问题