ASP.NET dynamometric modify the setup items in Web.config (CS page code)

xiaoxiao2021-03-06  15

using System; using System.Collections; using System.ComponentModel; using System.Data; using System.Drawing; using System.Web; using System.Web.SessionState; using System.Web.UI; using System.Web.UI.WebControls Using system.web.ui.htmlcontrols; using system.xml;

namespace WebApplication1 {///

/// Summary description for WebForm1./// public class WebForm1: System.Web.UI.Page {protected System.Web.UI.WebControls.TextBox TextBox1; protected System .Web.ui.WebControls.dropdownlist DropdownList1; protected system.web.ui.WebControls.Button Button1;

Public Webform1 () {page.init = new system.eventhandler (Page_init);

Private void page_load (object sender, system.eventargs e) {if (! page.ispostback) {// Open a file (assuming web.config in the root directory) String filename = server.mAppath ("/") @ " /Web.config"; xmldocument xmldoc = new xmldocument (); xmldoc.load (filename);

XmlNodeList topM = xmldoc.DocumentElement.ChildNodes; foreach (XmlElement element in topM) {if (element.Name.ToLower () == "appsettings") {XmlNodeList _node = element.ChildNodes; if (_node.Count> 0) {DropDownList1 .Items.clear (); foreach (xmlelement el in _node) {DropDownList1.items.add (el.attributes ["key"]. Innerxml;}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}

Private void Page_init (Object Sender, Eventargs E) {INITIALIZEComponent ();

#region Web Form Designer generated code ///

/// Required method for Designer support - do not modify /// the contents of this method with the code editor./// private void InitializeComponent () {This.button1.click = new system.eventhandler (this.button1_click; this.load = new system.eventhandler (this.page_load);

} #endregion

private void Button1_Click (object sender, System.EventArgs e) {string filename = Server.MapPath ( "/") @ "/ web.config"; XmlDocument xmldoc = new XmlDocument (); xmldoc.Load (filename); XmlNodeList topM = xmldoc.DocumentElement.ChildNodes; foreach (XmlElement element in topM) {if (element.Name.ToLower () == "appsettings") {XmlNodeList _node = element.ChildNodes; if (_node.Count> 0) {foreach (XmlElement El in _Node) {if (El.attributes ["key"]. Innerxml.tolower () == this.dropdownList1.selectedItem.Value.tolower ()) {el.attributes ["value"]. value = this.TextBox1 .Text;}}}}} xmldoc.save (filename);}}}

转载请注明原文地址:https://www.9cbs.com/read-65124.html

New Post(0)