中文字幕日韩一区二区_国产一区二区av_国产毛片av_久久久久国产一区_色婷婷电影_国产一区二区精品

ASP.NET(C#)應(yīng)用程序配置文件app.config/web.config的增、刪、改操作

配置文件,對(duì)于程序本身來說,就是基礎(chǔ)和依據(jù),其本質(zhì)是一個(gè)xml文件,對(duì)于配置文件的操作,從.NET 2.0 開始,就非常方便了,提供了 System [.Web] .Configuration 這個(gè)管理功能的NameSpace,要使用它,需要添加對(duì) System.configuration.dll的引用。
對(duì)于WINFORM程序,使用 System.Configuration.ConfigurationManager;
對(duì)于ASP.NET 程序, 使用 System.Web.Configuration.WebConfigurationManager;
對(duì)于配置文件內(nèi)容的讀取,真是太普遍不過了,如果你的程序里,沒有讀取配置文件內(nèi)容的方面,你都不好意思拿出來用
我們以最常見的 AppSettings 小節(jié)來作為例子:
假設(shè)有如下的配置文件內(nèi)容:
復(fù)制代碼 代碼如下:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<appSettings>
<add key="y" value="this is Y"/>
</appSettings>
</configuration>

1. 讀取值:
* ASP.NET: System.Web.Configuration.WebConfigurationManager.AppSettings[“y”];
* WinForm: System.Configuration.ConfigurationManager.AppSettings[“y”];
2. 添加一項(xiàng)
ASP.NET(需要有寫權(quán)限):
Configuration config = WebConfigurationManager.OpenWebConfiguration(null);
AppSettingsSection app = config.AppSettings;
app.Settings.Add("x", "this is X");
config.Save(ConfigurationSaveMode.Modified);
WinForm:
Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
AppSettingsSection app = config.AppSettings;
app.Settings.Add("x", "this is X");
config.Save(ConfigurationSaveMode.Modified);
3. 修改一項(xiàng)
* ASP.NET
Configuration config = WebConfigurationManager.OpenWebConfiguration(null);
AppSettingsSection app = config.AppSettings;
//app.Settings.Add("x", "this is X");
app.Settings["x"].Value = "this is not Y";
config.Save(ConfigurationSaveMode.Modified);
* WinForm
Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
AppSettingsSection app = config.AppSettings;
//app.Settings.Add("x", "this is X");
app.Settings["x"].Value = "this is not Y";
config.Save(ConfigurationSaveMode.Modified);
4. 刪除一項(xiàng)
* ASP.NET
Configuration config = WebConfigurationManager.OpenWebConfiguration(null);
AppSettingsSection app = config.AppSettings;
app.Settings.Remove("x");
config.Save(ConfigurationSaveMode.Modified);
* WinForm
Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
AppSettingsSection app = config.AppSettings;
app.Settings.Remove("x");
config.Save(ConfigurationSaveMode.Modified);

AspNet技術(shù)ASP.NET(C#)應(yīng)用程序配置文件app.config/web.config的增、刪、改操作,轉(zhuǎn)載需保留來源!

鄭重聲明:本文版權(quán)歸原作者所有,轉(zhuǎn)載文章僅為傳播更多信息之目的,如作者信息標(biāo)記有誤,請(qǐng)第一時(shí)間聯(lián)系我們修改或刪除,多謝。

主站蜘蛛池模板: 久久精品欧美电影 | av一区二区三区 | 懂色av一区二区三区在线播放 | 欧美成视频| 国产精品99久久久久久www | 欧美成年视频 | 欧美精品91 | 中文字幕日韩欧美一区二区三区 | 91在线精品一区二区 | 久久综合色综合 | 国产伦一区二区三区 | 午夜视频网站 | 国产色视频网站 | 日韩成人免费av | 精品国产一区二区三区久久狼黑人 | 日韩亚洲视频 | 一区二区三区视频在线 | 精品久久中文字幕 | 国产视频一区在线观看 | 毛色毛片免费看 | 久久久久久久av麻豆果冻 | 国产色网站 | 亚洲91精品 | 成人免费在线 | 丝袜一区二区三区 | 日本精品一区二区三区在线观看 | 久久99精品久久久久久琪琪 | 亚洲精品电影在线观看 | 啪啪免费网 | www.亚洲一区 | 亚洲精品在线播放 | 亚洲视频在线观看 | 999精品网 | 97avcc| 国产精品成人国产乱一区 | 日本一区二区在线视频 | 伊人色综合久久天天五月婷 | 国产精品久久久久久52avav | 日韩精品久久久久久 | 青青草综合网 | 亚洲视频一区二区三区 |