Click here to Skip to main content
15,891,372 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hai
How to change the value in config file,so only can get updated value in next time.
i can easily get the value from config file like

VB
Dim radbtnBrowseSLD As String = System.Configuration.ConfigurationManager.AppSettings("radbtnBrowseSLD")


but if i try to update the new value it not update but code executes successfully like
VB
System.Configuration.ConfigurationManager.AppSettings.Set("radbtnBrowseSLD")="newvalue"


but value not updated when i see in App.config file.

pls reply me how to change App.config file.


Regards
AravindB
Posted

Try this:

VB
Dim config As Configuration =ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None)

config.AppSettings.Settings("radbtnBrowseSLD").Value = "newvalue"

config.Save(ConfigurationSaveMode.Modified)

ConfigurationManager.RefreshSection("appSettings")


But it do'nt refresh app.config.for this you go to bin folder and find the .exe.config and run it with F5. also you can see this for C#:

http://stackoverflow.com/questions/1357240/change-the-value-in-app-config-file-dynamicallay[^]
 
Share this answer
 
v4
I would recommend against changing the web.config file through code: IIS and user sessions cache that information, which means it may not propagate in the way you want. Some changes may also force IIS to recompile your website, which can cause user issues.

With the sites I do, web.config holds only global settings that rarely, if ever, need to be changed, such as the copyright message and the page with the "No Permissions" message. More flexible data is stored in individual XML files within the App_Data folder. One file, GlobalConfig.xml, holds site-wide data such as whether or not the site is down for maintenance; other files hold details about our current continuing education requirements, or details about contacts. All of these files are managed by the same block of code, written to create an interface very similar to the Configuration class. These files can all be changed without touching web.config, and the access toolkit is written to de-cache and reload if the file has been changed, putting data management in your hands rather than the Framework's.

I've been looking to write another article for CP; this might be a good one to do.
 
Share this answer
 
Comments
Aravindba 4-Dec-13 20:32pm    
thank u for ur reply for changing web.config for web application,but i ask for app.config ,that is related to windows application,in each line i am specified app.config word,so pls read clearly then reply.anyway thank u for ur reply this is also i need in future.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900