Wir haben eine Anwendung, die eine Datei exe.config viel wie dieses hat:Wie aktualisiere ich die .NET-Konfiguration in einem benutzerdefinierten Konfigurationsabschnitt?
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<sectionGroup name="ConsoleSettings">
<section name="Console" type="MyApp.ConfigSection" allowLocation="true" allowDefinition="Everywhere" />
</sectionGroup>
</configSections>
<ConsoleSettings>
<Console Username="User" Password="user" LanAddress="192.168.42.11" Port="8792" />
</ConsoleSettings>
....
Was ich die Datei lesen tun möchte ist, ändern Sie die LanAddress etwas der Benutzer (etwa string newLanAddress
) eingegeben und dann Speichere es zurück.
Bisher habe ich dies:
var configFile = new ExeConfigurationFileMap();
var configFile.ExeConfigFilename = "MyApp.exe.config";
var config = ConfigurationManager.OpenMappedExeConfiguration(configFile, ConfigurationUserLevel.None);
var configGroup = config.SectionGroups[@"ConsoleSettings"];
var consoleSection = configGroup.Sections[0];
var lanAddress = consoleSection.// this is where I get stuck
Wie greife ich auf das LanAddress Element consoleSection ??
Können Sie nicht bekommen Sie den Wert mit 'System.Configuration.ConfigurationManager.AppSettings [key];' – Jacobr365