




版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(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è)試頁面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. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 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ì)自己和他人造成任何形式的傷害或損失。
最新文檔
- 新疆烏魯木齊市沙依巴克區(qū)烏魯木齊四中2025年高三下學(xué)期第二次月考數(shù)學(xué)試題文試題含解析
- 新鄉(xiāng)醫(yī)學(xué)院三全學(xué)院《物理化學(xué)實(shí)驗(yàn)B》2023-2024學(xué)年第二學(xué)期期末試卷
- 2025至2031年中國(guó)碳化硅燒嘴套行業(yè)投資前景及策略咨詢研究報(bào)告
- 興義民族師范學(xué)院《社會(huì)統(tǒng)計(jì)與spss應(yīng)用》2023-2024學(xué)年第二學(xué)期期末試卷
- 廣東滄江中學(xué)2024屆中考數(shù)學(xué)全真模擬試卷含解析
- 2025項(xiàng)目部管理人員安全培訓(xùn)考試試題(真題匯編)
- 25年公司、項(xiàng)目部、各個(gè)班組三級(jí)安全培訓(xùn)考試試題含答案(B卷)
- 2025公司廠級(jí)員工安全培訓(xùn)考試試題含答案【新】
- 2025年廠里職工安全培訓(xùn)考試試題含完整答案【奪冠系列】
- 2025崗位安全培訓(xùn)考試試題綜合卷
- 2025年上半年福建福州廣播電視臺(tái)招聘易考易錯(cuò)模擬試題(共500題)試卷后附參考答案
- 2025年北師大版物理中考一輪備考復(fù)習(xí):光現(xiàn)象、透鏡作圖專題(一)(含解析)
- 遼寧協(xié)作校2024-2025學(xué)年度下學(xué)期高三第二次模擬考試語文試卷(含答案解析)
- 2025-2030汽車揚(yáng)聲器市場(chǎng)發(fā)展現(xiàn)狀分析及行業(yè)投資戰(zhàn)略研究報(bào)告
- 期中考試考后分析總結(jié)主題班會(huì)《全員出動(dòng)尋找消失的分?jǐn)?shù)》
- 成都樹德中學(xué)2025年高三第四次聯(lián)考物理試題文試卷
- 2025-2030中國(guó)數(shù)據(jù)安全服務(wù)行業(yè)市場(chǎng)深度分析及前景趨勢(shì)與投資研究報(bào)告
- 山東省天一大聯(lián)考·齊魯名校教研體2024-2025學(xué)年(下)高三年級(jí)第六次聯(lián)考(物理試題及答案)
- 2024年秦皇島市市屬事業(yè)單位考試真題
- 特種設(shè)備“日管控、周排查、月調(diào)度”表格
- 父母委托子女保管存款協(xié)議書
評(píng)論
0/150
提交評(píng)論