Configuration class make it able to add the key and value pair of data, then it saves them in pre-opened web configuration file.
In the following example, we have two textbox controls which user can enter the key and value and add them to the Web.Config file if they are not empty.
using System.Configuration;
using System.Web.Configuration;
...
if(txtKey.Text == String.Empty ||
txtVal.Text == String.Empty)
return;
Configuration cnfg =
WebConfigurationManager.OpenWebConfiguration("~");
cnfg.AppSettings.Settings.Add(txtKey.Text,txtVal.Text);
cnfg.Save();
...
No comments:
Post a Comment