Is there a way to programmatically save values to

2019-07-14 15:07发布

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();

2条回答
不美不萌又怎样
2楼-- · 2019-07-14 15:55

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

查看更多
别忘想泡老子
3楼-- · 2019-07-14 16:10

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

查看更多
登录 后发表回答