Development Notes: Quick configuration of Web. config

Source: Internet
Author: User
Development Notes: Quick configuration of Web. config

Development Notes: Quick configuration of Web. config

Author: anytao

 

Problem description:

In web development. cofig does not work as a technician, but it is often necessary for the customer to perform simple configuration on their own. It is necessary to provide an effective tool to guide the customer to complete this operation, and prevent invalid or incorrect changes.

Solution:

First, you must understand that the System Configuration mainly includes machine. config and web. config. These two files are essentially XML files that contain all the configuration information of ASP. NET. Therefore, the configuration of the system is actually an operation on the XML file. Therefore, we can adopt the read and write operations on the XML file to achieve quick configuration. Here, we take Web. config as an example to illustrate that the content of each data item in Web. config is not the focus of the discussion. For details, refer to the description of msdn.

Core of implementationCodeIs:

Private void btnok_click (Object sender, system. eventargs E)
{
// Define variables
String strlocation = txtlocation. text;
String strprovider = txtprovider. text;
String strmode = txtmode. text;
String struser = txtuser. text;
String strdatasource = txtdatasource. text;
String strpwd = txtpwd. text;

String semicolon = ";";

// Operate XML nodes
Xmldocument xmldoc = new xmldocument ();
Xmldoc. Load ("myxml. xml ");
Xmlnode xnode = xmldoc. selectsinglenode ("// deleteapps/ add [@ key = 'oledbconnection1. connectionstring ']");
If (xnode! = NULL)
{
Xnode. attributes ["value"]. value = "location =" + strlocation + semicolon + "provider =" + strprovider + semicolon +
"Mode =" + strmode + semicolon + "User ID =" + struser + semicolon + "Data Source =" + strdatasource + semicolon +
"Password =" + strpwd;
}
Xmldoc. Save ("myxml. xml ");

MessageBox. Show ("set successfully! ");
}

In the code, we use myxml. XML as an example to represent any other XML modifications.

These are just simple operations on a data item, and further operations need to be improved.

On the following operation interface, non-technical personnel can easily modify the information.

I hope you can give me more comments. If you need to discuss the code or leave it in your mailbox, I hope you will have a smile.

Enjoy.

Contact Us

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

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.