




版權(quán)說(shuō)明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡(jiǎn)介
1、1.建立一個(gè)class,ReadWriteConfig.csusing System;using System.Configuration;using System.Reflection;using System.Web;using System.Xml;public enum ConfigFileType WebConfig, AppConfignamespace WebApplication1
2、160; /*/ <summary> / Summary description for ReadWriteConfig. / </summary> public class ReadWriteConfig
3、; public string docName = String.Empty; private XmlNode node=null; private int _configTyp
4、e; public int ConfigType get return _configType;
5、 set _configType=value; SetValue#region SetValue public bool SetValue(string key, strin
6、g value) XmlDocument cfgDoc = new XmlDocument(); loadConfigDoc(cfgDoc);
7、160; / retrieve the appSettings node node = cfgDoc.SelectSingleNode("/appSettings");
8、0; if( node = null )
9、60;throw new InvalidOperationException( "appSettings section not found"); try
10、0; / XPath select setting "add" element that contains this k
11、ey XmlElement addElem= (XmlElement)node.SelectSingleNode("/addkey='" +key +"'")
12、 if(addElem!=null) a
13、ddElem.SetAttribute("value",value); / not found, so we&
14、#160;need to add the element, key and value else
15、160; XmlElement entry = cfgDoc.CreateElement("add");
16、160;entry.SetAttribute("key",key); entry.SetAttribute("value",value);
17、160; node.AppendChild(entry);
18、160; /save it saveConfigDoc(cfgDoc,docName); return true;
19、160; catch
20、60; return false; #endregio
21、n saveConfigDoc#region saveConfigDoc private void saveConfigDoc(XmlDocument cfgDoc,string cfgDocPath)
22、160; try XmlTextWriter writer = new XmlTextWriter( cfgDocPath ,
23、;null ); writer.Formatting = Formatting.Indented; cfgDoc.WriteTo(
24、 writer ); writer.Flush(); writer.Close();
25、0; return; catch
26、0; throw;
27、0; #endregion removeElement#region removeElement public bool removeElement (string elementKey)
28、0; try XmlDocument
29、160;cfgDoc = new XmlDocument(); loadConfigDoc(cfgDoc); / retrieve t
30、he appSettings node node = cfgDoc.SelectSingleNode("/appSettings");
31、 if( node = null ) throw new Inv
32、alidOperationException( "appSettings section not found");
33、60; / XPath select setting "add" element that contains this key to remove node.RemoveChild( no
34、de.SelectSingleNode("/addkey='" +elementKey +"'") ); saveConfigDoc(cfgDoc,docName); &
35、#160; return true; catch
36、60; return false;
37、60; #endregion modifyElement#region modifyElement public bool modifyElement (string elementKey)
38、60; try XmlDocument cfgDoc =
39、new XmlDocument(); loadConfigDoc(cfgDoc); / retrieve the appSettings
40、0;node node = cfgDoc.SelectSingleNode("/appSettings");
41、;if( node = null ) throw new InvalidOperationException(
42、 "appSettings section not found"); / XPath
43、160;select setting "add" element that contains this key to remove node.RemoveChild(node.SelectSingleNode("/ad
44、dkey='" +elementKey +"'"); saveConfigDoc(cfgDoc,docName); r
45、eturn true; catch
46、60; return false; #endregion
47、; loadConfigDoc#region loadConfigDoc private XmlDocument loadConfigDoc( XmlDocument cfgDoc )
48、 / load the config file if( Convert.ToInt32(ConfigType)=Convert.ToInt32(ConfigFileType.AppConfig)
49、 docName= (Assembly.GetEntryAssembly().GetName().Name;
50、160; docName += ".exe.config" else
51、160; cfgDoc.Load( docName ); return cfgDoc;
52、0; #endregion 2.建立測(cè)試頁(yè)面2.1 html<HTML> <HEAD> <title>WebForm1</title>
53、60; <meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1"> <meta name="CODE_LANGUAGE" Content="C#">
54、60; <meta name="vs_defaultClientScript" content="JavaScript"> <meta name="vs_targetSchema" content </HEAD> <body MS_POSITIONING=&
55、quot;GridLayout"> <form id="Form1" method="post" runat="server"> <asp:Button id="Button1" style=&quo
56、t;Z-INDEX: 101; LEFT: 296px; POSITION: absolute; TOP: 120px" runat="server" Text="刪除"></asp:Button>
57、160; <asp:Button id="Button2" style="Z-INDEX: 102; LEFT: 232px; POSITION: absolute; TOP: 120px" runat="server"
58、 Text="新增"></asp:Button> <asp:Label id="Label1" style="Z-INDEX: 103; LEFT: 104px; POSITION: absolute; TOP: 32px" r
59、unat="server">key</asp:Label> <asp:TextBox id="TextBox1" style="Z-INDEX: 104; LEFT: 168px; POSITION: absolute; TOP: 32px" runat="ser
60、ver"></asp:TextBox> <asp:Label id="Label2" style="Z-INDEX: 105; LEFT: 104px; POSITION: absolute; TOP: 96px" runat="server">value&
61、lt;/asp:Label> <asp:TextBox id="TextBox2" style="Z-INDEX: 106; LEFT: 168px; POSITION: absolute; TOP: 80px" runat="server"></asp:TextBox&g
62、t; <asp:Button id="Button3" style="Z-INDEX: 107; LEFT: 360px; POSITION: absolute; TOP: 120px" runat="server"
63、160; Text="修改"></asp:Button> </form> </body></HTML>2.2 cs代碼public class
64、0; protected protected protected protected protected protect
65、ed protected private void Page_Load(object sender, System.EventArgs e)
66、60; Web Form Designer generated code#region Web Form Designer generated code overri
67、de protected void OnInit(EventArgs e) / / CODEGEN: This call is r
68、equired by the ASP.NET Web Form Designer. / InitializeComponent();
69、160; base.OnInit(e); /*/ <summary> / Required method for Designer sup
70、port - do not modify / the contents of this method with the code editor. / </summary>
71、60;private void InitializeComponent() this.Button1.Click += new System.EventHandler(this.Button1_Click);
72、0; this.Button2.Click += new System.EventHandler(this.Button2_Click); this.Button3.Click += new System.EventHandler(this.Button3_Click); this
溫馨提示
- 1. 本站所有資源如無(wú)特殊說(shuō)明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒(méi)有圖紙預(yù)覽就沒(méi)有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫(kù)網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。
最新文檔
- 認(rèn)知心理學(xué)課程體系構(gòu)建與教學(xué)實(shí)踐探索
- 泉水蜜桃貯藏保鮮技術(shù)影響因素探究
- 教育大數(shù)據(jù)學(xué)習(xí)行為的深度挖掘
- 安全生產(chǎn)排查表怎么填寫
- 崗位述職個(gè)人述職報(bào)告
- 情感智力在學(xué)業(yè)成就中的實(shí)踐應(yīng)用
- 普外科模擬練習(xí)題與答案
- 醫(yī)學(xué)美容教育認(rèn)證體系的政策支持與實(shí)施
- 醫(yī)學(xué)心理倫理學(xué)測(cè)試題
- 技術(shù)賦能教育在安全環(huán)境中實(shí)現(xiàn)創(chuàng)新
- 西安高新區(qū)管委會(huì)招聘考試真題2024
- 黨史知識(shí)競(jìng)賽試題及答案
- 隧道建設(shè)施工進(jìn)度計(jì)劃與工期保證措施
- 車工考評(píng)員培訓(xùn)課件
- 站姿走姿坐姿禮儀培訓(xùn)
- 小規(guī)模稅務(wù)視頻教學(xué)課件
- 業(yè)務(wù)外包費(fèi)用管理制度
- 痛風(fēng)的康復(fù)護(hù)理課件
- 公司自供自產(chǎn)品管理制度
- 五育并舉與心理健康教育的融合
- 介入室耗材管理課件
評(píng)論
0/150
提交評(píng)論