網站安裝打包 修改app.config[六]

來源:互聯網
上載者:User

在winform的安裝工具中,少不免有一些設定檔要放到app.config去,於是修改也是成了一種需求!

無論是修改web.config還是app.config,普遍方式都有兩種,用net內建封裝的類,或是自訂xml操作。

可參考之前的一篇:網站安裝打包 webconfig修改[三]

這裡用的,還是以xml方式操作,比竟類都寫了,就順路用上了。

這裡的操作方式和webconfig的差不多一個樣:

 

修改app.config

 string appConfigPath = startPath + "/XXX.exe.config";
                WebConfigHelper appConfig = new WebConfigHelper(appConfigPath);
                if (appConfig.LoadIsOK)
                {
                    WebConfigAppSetting appSetting = appConfig.AppSetting;
                    if (appSetting != null)
                    {
                      
                        appSetting.Set("SoftSetup_WinRARSystemPath", txtSoftSetup_WinRARSystemPath.Text);
                        appSetting.Set("SoftSetup_IISPath", txtSoftSetup_IISPath.Text.Replace(startPath, ""));
                    }
                    if (appConfig.Save())
                    {
                        ConfigurationManager.RefreshSection("appSettings");
                        MessageBox.Show("修改成功!"); return;
                    }
                }
                MessageBox.Show("修改失敗!");

 

 

這裡最值得一提的一句是:ConfigurationManager.RefreshSection("appSettings");

修改完app.config時,雖然是修改了檔案,但運行在記憶體中的app.config卻還沒有修改.

所以你改完檔案,再取值,還是記憶體中的舊值,因此修改完後,需要重新載入一下。

 

打完,收工!

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.