Is it possible to create a * .config file from scratch programmatically in .NET (C #)?

For our approach, we want to create one of the * .config files from scratch and fill it with some standard / custom values ​​at runtime.

Is there any way to do this programmatically through the ConfigurationManager or something like that?

+3
source share
3 answers

Yes. As you noticed, the class ConfigurationManagerallows you to read and write configuration files.

ConfigurationManager Class

Scroll down a bit.

Of course, you can read / write these files as XML files, but the above class provides a convenient interface for managing configuration files.

ConfigurationManager, , [ab?] ExeConfigurationFileMap. , file , , Save()

ExeConfigurationFileMap fileMap = new ExeConfigurationFileMap
{
    ExeConfigFilename = file
};
var config = ConfigurationManager.OpenMappedExeConfiguration(fileMap, ConfigurationUserLevel.None);
//todo manipulate config. add settings / connection strings etc.
config.Save();
+7

.config - XML, XmlTextWriter .

+3

, xml

... config ? app.config? web.config? custom.config?

Windows -, , ( , , / , , ..)

0
source

Source: https://habr.com/ru/post/1767524/


All Articles