Asp. NET program to dynamically modify the setup items in Web.config (background CS code)
Source: Internet
Author: User
web| Program | news | backstage | Project friends can test on their own, I have no problem here, Turtle had a morning's problem finally solved
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>
Summary description for WebForm1.
</summary>
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 the 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);
}
}
}
}
}
}
#region Web Form Designer generated code
<summary>
Required to Designer support-do not modify
The contents is with the Code Editor.
</summary>
private void InitializeComponent ()
{
This. Button1.Click + = new System.EventHandler (this. Button1_Click);
This. Load + = new System.EventHandler (this. Page_Load);
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.
A Free Trial That Lets You Build Big!
Start building with 50+ products and up to 12 months usage for Elastic Compute Service