M
Martin Hart
Hi:
I am having trouble writing to an external .config file (a .config file
from another application, not the running application)
Below I have included the code I am using, but although no exception or
error is thrown, noting is written to the file! All the sections and
elements exist in the .config file and the debugger passes through each
scenario.
Can anyone please help me?
TIA,
Martin.
Code
****
private void saveToExternalConfigFile()
{
ExeConfigurationFileMap fileMap = new ExeConfigurationFileMap();
fileMap.ExeConfigFilename = @"MovilGesNet.exe.config";
Configuration config =
ConfigurationManager.OpenMappedExeConfiguration(fileMap,
ConfigurationUserLevel.None);
ConfigurationSectionGroup seccion =
config.GetSectionGroup("applicationSettings");
if(seccion != null)
{
ClientSettingsSection secPropertiesSettings =
seccion.Sections["MovilGesNet.Properties.Settings"] as
ClientSettingsSection;
if(secPropertiesSettings != null)
{
foreach(SettingElement element in secPropertiesSettings.Settings)
{
switch(element.Name)
{
case "Host":
element.Value.ValueXml.InnerText = "MyNewAppText";
break;
}
}
}
}
seccion = config.GetSectionGroup("userSettings");
if(seccion != null)
{
ClientSettingsSection secPropertiesSettings =
seccion.Sections["MovilGesNet.Properties.Settings"] as
ClientSettingsSection;
if(secPropertiesSettings != null)
{
foreach(SettingElement element in secPropertiesSettings.Settings)
{
switch(element.Name)
{
case "PathPdaImport":
element.Value.ValueXml.InnerText = "MyNewUserText";
break;
}
}
}
}
config.Save(ConfigurationSaveMode.Full); // Not doing anything!
}
I am having trouble writing to an external .config file (a .config file
from another application, not the running application)
Below I have included the code I am using, but although no exception or
error is thrown, noting is written to the file! All the sections and
elements exist in the .config file and the debugger passes through each
scenario.
Can anyone please help me?
TIA,
Martin.
Code
****
private void saveToExternalConfigFile()
{
ExeConfigurationFileMap fileMap = new ExeConfigurationFileMap();
fileMap.ExeConfigFilename = @"MovilGesNet.exe.config";
Configuration config =
ConfigurationManager.OpenMappedExeConfiguration(fileMap,
ConfigurationUserLevel.None);
ConfigurationSectionGroup seccion =
config.GetSectionGroup("applicationSettings");
if(seccion != null)
{
ClientSettingsSection secPropertiesSettings =
seccion.Sections["MovilGesNet.Properties.Settings"] as
ClientSettingsSection;
if(secPropertiesSettings != null)
{
foreach(SettingElement element in secPropertiesSettings.Settings)
{
switch(element.Name)
{
case "Host":
element.Value.ValueXml.InnerText = "MyNewAppText";
break;
}
}
}
}
seccion = config.GetSectionGroup("userSettings");
if(seccion != null)
{
ClientSettingsSection secPropertiesSettings =
seccion.Sections["MovilGesNet.Properties.Settings"] as
ClientSettingsSection;
if(secPropertiesSettings != null)
{
foreach(SettingElement element in secPropertiesSettings.Settings)
{
switch(element.Name)
{
case "PathPdaImport":
element.Value.ValueXml.InnerText = "MyNewUserText";
break;
}
}
}
}
config.Save(ConfigurationSaveMode.Full); // Not doing anything!
}