0

Here is my AppConfig File

<?xml version="1.0" encoding="utf-8"?>
<configuration>
    <startup> 
        <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5"/>
    </startup>
  <connectionStrings>
    <add name="Connection" connectionString="(local)\SQLexpress"/>
    <add name="MainPrinter" connectionString=""/>
  </connectionStrings>

</configuration>

And I want to change MainPrinter's Name

Here is what i'm trying to do:

Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
config.AppSettings.Settings["MainPrinter"].Value = "Epson";
config.Save(ConfigurationSaveMode.Modified);
ConfigurationManager.RefreshSection("connectionStrings");

But i dont take any result

maccettura
  • 10,514
  • 3
  • 28
  • 35
Dim
  • 41
  • 8
  • 1
    Don't use AppConfig as a persistence. You should not be modifying the values in code. 99.9% of the time you should consider it "read only" – maccettura Feb 16 '18 at 17:20
  • ok is it better to create a txt file? – Dim Feb 16 '18 at 17:24
  • 1
    No, its better to just set the connection string for MainPrinter and leave it alone. If you need different values for different environments then you would use Config Transforms – maccettura Feb 16 '18 at 17:25
  • Can you give me an example? I need my client to change it inside my application – Dim Feb 16 '18 at 17:26
  • 1
    Possible duplicate of [Change connection string & reload app.config at run time](https://stackoverflow.com/questions/502411/change-connection-string-reload-app-config-at-run-time) – WorkSmarter Feb 16 '18 at 18:11

0 Answers0