In this tutorial I will show you how to modify the AppSettings value in web.config file programmatically. Here, I am updating the app key value of petrol, diesel, oil prices and save the appsettings.you can create textboxs and update button. When the user want to change the price then entering the value in textboxes, on button click you can update the appsettings value.
Web.config Code:
<appSettings>
<add key="PetrolRate" value="112.53" />
<add key="DieselRate" value="101.36" />
<add key="OilRate" value="312" />
</appSettings>
C# Code:
// to
open the configuration file
Configuration
webConfigApp = WebConfigurationManager.OpenWebConfiguration("~");
//
changing the app key value
webConfigApp.AppSettings.Settings["PetrolRate"].Value = "112.53";
webConfigApp.AppSettings.Settings["DieselRate"].Value = "101.36";
webConfigApp.AppSettings.Settings["OilRate"].Value = "312";
// save
the appsettings
webConfigApp.Save();
Post your comments / questions
Recent Article
- How to use if else statement in c++?
- How to use godaddy domain name with another godaddy hosting account?
- Restore of database 'DATABASE' failed. (Microsoft.SqlServer.Management.RelationalEngineTasks)
- TypeError [ERR_INVALID_CALLBACK]: Callback must be a function. Received undefined
- How to calculate the age from jQuery ui datepicker using c#?
- How to calculate days difference between two dates in c#?
- Changing date format in jQuery ui datepicker
- How to set value to nicedit textarea using jQuery?
Related Article