[Go]c# configuration file

Source: Internet
Author: User

Configuration files are used in many cases, and the configuration file is divided into two types: the application configuration file and the Web configuration file.

The biggest difference between the two profiles is that the Web's profile updates are updated in real time and the application's configuration files are not updated in real time.

Refresh the application's configuration file after you update it

Configurationmanager.refreshsection ("appSettings");//refreshes the named section and re-reads it from disk the next time it is retrieved.
ConfigurationSettings also has this problem, but I don't know how to refresh the node,
< Configuration >   < appSettings >     <  key= "name"  value= "I am a remote server"/>   </  appSettings></configuration >  Background program is worth reading: string s=system.configuration.configurationsettings.appsettings["name"];

system.configuration.configurationsettings.appsettings["Key"];
But now FrameWork2.0 has made it clear that this property is obsolete. It is recommended to change to ConfigurationManager or WebConfigurationManager. And the AppSettings property is read-only and does not support modifying property values.

However, to invoke ConfigurationManager, you must first add a reference to the System.Configuration.dll assembly in the project. (Right-click the project name in the Solution Manager, select Add Reference in the right-click menu, find it under. NET Tablepage) Add reference can be used with String str = configurationmanager.appsettings["Key"] To get the corresponding value.

To update a configuration file:
Configuration CFA = configurationmanager.openexeconfiguration (Configurationuserlevel.none);
Add to

CfA. APPSETTINGS.SETTINGS.ADD ("Key", "Name")

Modify

CfA. appsettings.settings["Browsedir"]. Value = "name";

Last Call
CfA. Save ();
The current configuration file update was successful.

Configurationmanager.refreshsection ("appSettings");//refreshes the named section and re-reads it from disk the next time it is retrieved. Remember that the application will refresh the node

Connection string notation:

< connectionStrings >    <  name= "DefaultConnection"  connectionString= "Data source=.\sqlexpress; attachdbfilename=| Datadirectory|\aspnet-mvcweb-20150702180004.mdf;initial catalog=aspnet-mvcweb-20150702180004;integrated Security =true; User instance=true "  providerName=" System.Data.SqlClient "/>   </connectionStrings>

[Go]c# configuration file

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.