How to edit Configuration file Web.Config
How to edit Configuration file Web.Config
in web.config we use <appSettings> section to add keys as you see
<appSettings>
<add key="email" value="" />
<add key="color" value="green" />
</appSettings>
in code behind write this code to enable us reach to Keys and get value
Configuration conf = WebConfigurationManager.OpenWebConfiguration("~");
AppSettingsSection app = (AppSettingsSection)conf.GetSection("appSettings");
app.Settings["email"].Value = TextBox1.Text;
app.Settings.Add("color", "green");
conf.Save();
hope this useful
Revision number 2, Wednesday, August 22, 2012 2:43:13 PM by tmorton
You must Login to comment.
|
Tue, Aug 21, 2012 4:09 PM
by Afzaal.Ahmad.Zeeshan
|
I can understand the first code easily. But sorry to say about the second one. That's kinda difficult! Can I get inboxed for some elaborations?
|
|
Mon, Aug 27, 2012 7:58 AM
by damn code
|
Ok, The second part of this code. it talks about how to access appSettings keys to allow us adding, editing, removing specific key. Configuration conf = WebConfigurationManager.OpenWebConfiguration("~"); this means accessing to web.config file that allows us to access all sections in this file. AppSettingsSection app = (AppSettingsSection)conf.GetSection("appSettings"); this means accessing to specific section "appSettings". app.Settings["email"].Value = TextBox1.Text; here we have to make editing on value of "email" key. app.Settings.Add("color", "green"); in this line we have to make adding new key. finally we must save all changes using conf.Save();. hope to understand that clearly
|
Revision #2
Wed, Mar 23, 2011 8:31 PM
by
|
Employee Info Starter Kit - Getting Started
Employee Info Starter Kit is an open source ASP.NET project template that is intended to address different types of real world challenges faced by web application developers when performing common CRUD operations. Using a single database table ‘Employee’,
|