我正在尝试将连接字符串从 C:\test2\web.config 复制到 c:\test1\app.config。在 web.config 中,connectionString 元素如下所示。这两个配置文件都不属于我的项目。
ExeConfigurationFileMap fileMap = new ExeConfigurationFileMap();
fileMap.ExeConfigFilename = @"c:\test1\app.config";
Configuration config = ConfigurationManager.OpenMappedExeConfiguration(fileMap, ConfigurationUserLevel.None);
var connectionStringsSection = (ConnectionStringsSection)config.GetSection("connectionStrings");
ExeConfigurationFileMap fileMapWeb = new ExeConfigurationFileMap();
fileMapWeb.ExeConfigFilename = @"C:\test2\web.config";
Configuration configWeb = ConfigurationManager.OpenMappedExeConfiguration(fileMapWeb, ConfigurationUserLevel.None);
var connectionStringsWeb = (ConnectionStringsSection)configWeb.GetSection("connectionStrings");
//here I got connectionString element in connectionStringsWeb from web.config file. But how to append this connectionString element to app.config file.
提前致谢。