如何在vb.net中更改app.config文件中的值? [英] How to change value in app.config file in vb.net ?

查看:498
本文介绍了如何在vb.net中更改app.config文件中的值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

hai

如何更改配置文件中的值,以便下次只能获得更新值。

i可以轻松地从配置文件中获取值,如



  Dim  radbtnBrowseSLD  As  字符串 = System.Configuration.ConfigurationManager.AppSettings(  radbtnBrowseSLD





但如果我尝试更新新值,它不会更新但代码成功执行,例如

 System.Configuration.ConfigurationManager.AppSettings。 Set   radbtnBrowseSLD)=   newvalue 





但是当我在App.config文件中看到时,值没有更新。



请回复我如何更改App.config文件。





问候

AravindB

解决方案

试试这个:



 昏暗 config 作为 Configuration = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None)

config.AppSettings.Settings( radbtnBrowseSLD)。值= newvalue

config.Save(ConfigurationSaveMode.Modified)

ConfigurationManager.RefreshSection( appSettings





但它不刷新app.config 。为此,你去bin文件夹找到.exe.config并用F5运行它。你也可以看到这个C#:



http://stackoverflow.com/questions/1357240/change-the-value-in-app-config-file-dynamicallay [ ^ ]


< blockquote>我建​​议不要通过代码更改 web.config 文件:IIS和用户会话缓存该信息,这意味着它可能不会以您希望的方式传播。某些更改也可能会强制IIS重新编译您的网站,这可能会导致用户问题。



使用我做的网站, web.config 仅保留很少(如果有的话)需要更改的全局设置,例如版权消息和带有No Permissions消息的页面。更灵活的数据存储在 App_Data 文件夹中的各个XML文件中。一个文件 GlobalConfig.xml 保存站点范围内的数据,例如站点是否因维护而关闭;其他文件包含有关我们当前的继续教育要求或有关联系人的详细信息。所有这些文件都由相同的代码块管理,编写它们以创建一个非常类似于 Configuration 类的接口。这些文件都可以在不触及 web.config 的情况下进行更改,并且如果文件已经更改,则会将访问工具包写入de-cache并重新加载,将数据管理放在您的手中而不是框架。



我一直在寻找为CP写另一篇文章;这可能是一件好事。


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

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

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

解决方案

Try this:

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[^]


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.


这篇关于如何在vb.net中更改app.config文件中的值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆