日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

Asp.net使用代码修改配置文件的节点值

發布時間:2025/4/16 编程问答 24 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Asp.net使用代码修改配置文件的节点值 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

使用代碼修改配置文件的方法:

1、打開配置文件寫入的權限

2、先按節點名稱長到要修改的節點,然后刪除,緊接著將有新值的節點添加回去

3、關閉配置文件寫入的權限

修改Appsetting節點的值,修改其它節點的方法也差不多,也是找到要修改的節點刪除掉然后新新值的節點加上

public bool UpdateAppSettings(string key, string value){bool reuslt = false;try{Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);SetFileAccess(config.FilePath + "", false);ConfigurationSection sections = config.GetSection("appSettings");bool isSet = false;for (int i = 0; i < ((System.Configuration.AppSettingsSection)(sections)).Settings.Count; i++){string itemkey = ((System.Configuration.AppSettingsSection)(sections)).Settings.AllKeys[i];if (itemkey == key){((System.Configuration.AppSettingsSection)(sections)).Settings.Remove(key);((System.Configuration.AppSettingsSection)(sections)).Settings.Add(key, value);isSet = true;break;}}if (!isSet){((System.Configuration.AppSettingsSection)(sections)).Settings.Add(key, value);}config.Save();ConfigurationManager.RefreshSection("appSettings");SetFileAccess(config.FilePath + "", true);reuslt = true;}catch (Exception ex){LogNet.Log.WriteLog("UpdateAppSettings", ex);}return reuslt;} View Code

修改配置文件的讀寫權限

protected void SetFileAccess(string path, bool isReadOnly){FileInfo fi = new FileInfo(path);if (fi.IsReadOnly != isReadOnly)fi.IsReadOnly = isReadOnly;} View Code

?

轉載于:https://www.cnblogs.com/yonsy/p/5606920.html

總結

以上是生活随笔為你收集整理的Asp.net使用代码修改配置文件的节点值的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。