Ich habe diesen Code, um alle Schlüssel/Wert aus einer benutzerdefinierten .config
Datei zu erhalten, wo ich den Pfad übergeben, aber der Code ruft 0 Schlüssel, ich verstehe nicht warum .Code ruft keinen Schlüssel aus .config-Datei C#
Hier ist der Code:
public void UpdateService(string FilePathOld, string FilePathNew)
{
string[] Keys = { "SleepTimeInSeconds", "LogCleanInMinutes", "LogFileSize", "SqlTrans", "RemoteType", "DebugMode", "SleepError", "LogLevel", "LogSqlClient", "LogFile", "DebugRemote" };
Dictionary<string, string> Old = new Dictionary<string, string>();
Dictionary<string, string> New = new Dictionary<string, string>();
ExeConfigurationFileMap configOld = new ExeConfigurationFileMap();
configOld.ExeConfigFilename = FilePathOld;
Configuration config = ConfigurationManager.OpenMappedExeConfiguration(configOld, ConfigurationUserLevel.None);
ExeConfigurationFileMap configNew = new ExeConfigurationFileMap();
configNew.ExeConfigFilename = FilePathNew;
Configuration config2 = ConfigurationManager.OpenMappedExeConfiguration(configNew, ConfigurationUserLevel.None);
KeyValueConfigurationCollection settings = config.AppSettings.Settings;
Old = settings.AllKeys.ToDictionary(key => key, key => settings[key].Value);
KeyValueConfigurationCollection settings2 = config2.AppSettings.Settings;
New = settings2.AllKeys.ToDictionary(key => key, key => settings2[key].Value);
}
AppSettings oder Usersettings oder SomeOtherSettings? Prüfen Sie unter dem richtigen Knoten/Einstellungsnamen? Wenn möglich, zeigen Sie bitte auch die Konfigurationsdatei an. – touchofevil
Ich möchte alle Einstellungen im Abschnitt appSettings abrufen. Hier ist die Konfigurationsdatei: https://drive.google.com/file/d/0ByZb1KP9efohTDVhZXp1VkNBOEk/view?usp=sharing –
@touchofevil In den Code ich nicht angeben, welche Abschnitt möchte ich. Könnte es das sein? –