1

I'm fairly new to C# and have therfore not much insight on this kind of matter. Google search sadly yielded no help on that.

What actually is the difference between these two files? Which one is more important because they are (almost) identical?

And i have the need to programmically insert keys and values into the config but when i do that they are only insertet into the exe.config but i suppose that if i want to work with them i need them in the app.config, am i right? Everything thats in the config is in the exe.config, except when i add stuff programmically its added in the exe.config and how do i geht the added stuff into the app.config?

This is my code:

countComboBox = ComboBoxVersion.Items.Count;
Configuration config = ConfigurationManager.OpenExeConfiguration(System.IO.Path.Combine(Directory.GetCurrentDirectory(), "UpdatePackager.exe")); //exe path is for the config i suppose

for(int Vcount = 0; Vcount < countComboBox; Vcount++){
    config.AppSettings.Settings.Add(ComboBoxVersion.Items[Vcount].ToString() + "-DestinationpathClient" , "DateiPfad");
    config.AppSettings.Settings.Add(ComboBoxVersion.Items[Vcount].ToString() + "-DestinationpathUpdatePackages", "DateiPfad");
    config.Save(ConfigurationSaveMode.Minimal);
}           
LabelSourcepath.Content = SourcepathString;    
TextBoxDestinationpathUpdatePackage.Text = DestinationpathUpdatePackagesString;
TextBoxDestinationpathClient.Text = DestinationpathClientString;

I believe i miss something fundamental and would appreciate it if someone could make this clear to me. Regards

Liam
  • 27,717
  • 28
  • 128
  • 190
MansNotHot
  • 263
  • 1
  • 3
  • 19
  • 1
    There is no file named "app.config" or "exe.config", the configuration file for UpdatePackager.exe is UpdatePackager.exe.config. "app.config" only appears in the project, it is renamed at build time to match the exe name. The odds that Settings.Add() does anything useful in this case is never very high, the app has to be programmed to use these settings so the setting would already exist in the file. – Hans Passant Oct 05 '17 at 08:11
  • app.config is the template created and modified manually by you when you build your application. Then when you build the project is copied and renamed to exe.config in your output build folder. Your exe knows only about this file in the output folder, not the app.config in your project folder – Steve Oct 05 '17 at 08:14
  • @Steve And can i reach the exe.config so that i can get back the added keys into the program and use them for something? Maybe better formulated, am i able to write into the exe.config (done), later read out that stuff like it is possible with the normal app.config and use it? – MansNotHot Oct 05 '17 at 08:18
  • To which scope you add your new keys? If you add them to the user scope then they should persist between debug sessions. See [App.config User vs Application Setting](https://stackoverflow.com/questions/13046907/app-config-user-vs-application-scope) also https://learn.microsoft.com/en-us/dotnet/framework/winforms/advanced/using-application-settings-and-user-settings – Steve Oct 05 '17 at 08:39

0 Answers0