App.Config更改值這是我的App.Config<?xml version="1.0" encoding="utf-8" ?><configuration>
<appSettings>
<add key="lang" value="English"/>
</appSettings></configuration>使用此代碼,我進(jìn)行了更改lang = "Russian";private void Main_FormClosing(object sender, FormClosingEventArgs e){
System.Configuration.ConfigurationManager.AppSettings.Set("lang", lang);}但它沒有改變。我做錯(cuò)了什么?
3 回答

慕的地10843
TA貢獻(xiàn)1785條經(jīng)驗(yàn) 獲得超8個(gè)贊
當(dāng)使用“ ConfigurationUserLevel.None ”時(shí),當(dāng)您單擊調(diào)試文件夾中的nameyourapp.exe時(shí),您的代碼會(huì)正確運(yùn)行。。
但是當(dāng)你在visual stdio上開發(fā)應(yīng)用程序時(shí)沒有正確運(yùn)行!! 因?yàn)椤皏shost.exe”運(yùn)行。
以下參數(shù)解決了這個(gè)問題:“ Application.ExecutablePath ”
試試這個(gè):(在VS 2012 Express For Desktop中測試過)
Configuration config = ConfigurationManager.OpenExeConfiguration(Application.ExecutablePath);config.AppSettings.Settings["PortName"].Value = "com3";config.Save(ConfigurationSaveMode.Minimal);
我的英語不好,對不起。
- 3 回答
- 0 關(guān)注
- 448 瀏覽
添加回答
舉報(bào)
0/150
提交
取消