开发者

Is there a way to programmatically save values to web.config appSettings without destroying comments and formatting?

开发者 https://www.devze.com 2023-01-29 02:26 出处:网络
This code works, but it destroys comments and formatting 开发者_运维百科in Web.config.Is there a way to write to Web.config that won\'t destroy formatting?

This code works, but it destroys comments and formatting 开发者_运维百科in Web.config. Is there a way to write to Web.config that won't destroy formatting?

var webConfig = WebConfigurationManager.OpenWebConfiguration("~");
var settings = webConfig.AppSettings.Settings;
settings["Foo"].Value = "Bar";
webConfig.Save();


Maybe you can open the web.config as a standard xml file and use Xpath to locate the node you want to change.


You can use Visual Studio API, load Web.config and call Format Document against it

0

精彩评论

暂无评论...
验证码 换一张
取 消