本文介绍了将值设置为空/空自动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
您好我在App.Config中有以下代码,如何在运行后关闭程序时将其中的值设置为空。 FIY,该程序将被发布和部署。因此,用户只能更改App.Config中的值,而不能更改程序代码。
Hi i have the following codes in App.Config, how can i set the value in it to empty every time i close the program after i have run it. FIY, this program will be published and deployed. Therefore users can only change the value in App.Config and not the program codes.
<add key="EndDate" value=""/>
用户可以来App.Config并在每次运行程序时更改EndDate,但在关闭它之后,EndDate中的值将自动设置为空。
我试过这个但没有工作:
Users may come to App.Config and change the EndDate every time they run the program but after they close it, the value in EndDate will set to empty automatically.
I tried this but didnt work:
Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
config.AppSettings.Settings.Remove(StartDate);
config.AppSettings.Settings.Add(StartDate, "");
config.AppSettings.Settings.Remove(EndDate);
config.AppSettings.Settings.Add(EndDate, "");
config.Save(ConfigurationSaveMode.Modified);
推荐答案
这篇关于将值设置为空/空自动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!