2

I need to change my Webreference url in C# windows app. My app.config file has applicationSettings as

<applicationSettings>
    <DataAggregator.Properties.Settings>
        <setting name="DataAggregator_WebService_AccessDB"  serializeAs="String">
            <value>http://twks-126/Webservice/AccessDB.asmx</value>
        </setting>
    </DataAggregator.Properties.Settings>
</applicationSettings>

I need to change the value at runtime to new webservice. When I try to get the configurationmanager.appsettings I don't get the settings. Am I doing something wrong?

Thanks.

PhilMY
  • 2,621
  • 21
  • 29
Kenny
  • 819
  • 1
  • 9
  • 24

3 Answers3

0

Try changing the app.config configuration to the following;

<appSettings>
    <add key="DataAggregator_WebService_AccessDB" value="http://twks-126/Webservice/AccessDB.asmx"/>
</appSettings>
daryal
  • 14,643
  • 4
  • 38
  • 54
0

If you want to access the data pointed by <DataAggregator.Properties.Settings> you need to use this syntax in your code

string url = DataAggregator.Properties.Settings.Default.DataAggregator_WebService_AccessDB;

Keep in mind however that, if this settings has been configured as an Application Scope you will not be able to save changes back to the configuration file.

Your syntax could be used to access a different section of you config file. This section is called AppSettings and it's not the same as applicationSettings

Steve
  • 213,761
  • 22
  • 232
  • 286
0
var config = ConfigurationManager.OpenExeConfiguration(Application.ExecutablePath);
config.AppSettings.Settings.Remove(key);
config.AppSettings.Settings.Add(key, value.ToString());
config.Save(ConfigurationSaveMode.Minimal);
ConfigurationManager.RefreshSection("appSettings");
Ali Dehqan
  • 461
  • 1
  • 8
  • 18