开发者

Overwrite app.config with the default one

How can I overwrite开发者_StackOverflow社区 the app.config file form the App Data folder with the default one by code?


Not sure what you mean but you can use at the configurationSettings class to manage settings, you can also use a simple Data.XML namespace and change the XML in the config file and save it back but just beware that it is not the recommanded. typically i have always created an config object that i read all the config file settings and use it as a singleton in my code. if you want you can add a save method to the class that saves back the config file if you want to persist the changes that your code makes to the config class.


You can use a settings file. The VS designer will generate a proxy class for you. For each entry you can specify in the properties window wether you want to "GenerateDefaultInCode" or not. This way, you can configure your settings in the app.config file under the "ApplicationsSettings" section and at the same time rely on default values (set via attributes in the proxy class) in the generated code.

See http://msdn.microsoft.com/en-us/library/aa730869(VS.80).aspx for how to add a .settings file to your project.

As pointed out here default values should be used with care because they can lead to error-prone behaviour when you deploy to a different environment.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜