Read and write operations for configuration files (app. config)

Source: Internet
Author: User

    1. Modify the app. Config file
 App.config文件编译生成后,产生两个文件(*.exe.config和*.vshost.exe.config) ,第一个文件为项目实际使用的配置文件,在程序运行中所做的更改都将被保存于此;第二个文件其实为原代码中“App.config”的同步文件,在程序运行中不会发生更改。
1stringAppPath =System.IO.Path.GetDirectoryName (System.Reflection.Assembly.GetExecutingAssembly (). Location);2             stringConfigFile = System.IO.Path.Combine (AppPath,"CmdDisPro.exe.config");3Execonfigurationfilemap Configfilemap =NewExeconfigurationfilemap ();4Configfilemap.execonfigfilename =ConfigFile;5System.Configuration.Configuration config = configurationmanager.openmappedexeconfiguration (Configfilemap, Configurationuserlevel.none,true);6 7             //Basic Settings8Config. appsettings.settings["SysName"]. Value =Ivmbasic.systename;9Config. appsettings.settings["Organname"]. Value =Ivmbasic.currentunit;TenConfig. appsettings.settings["Alarminitializationspan"]. Value =Ivmbasic.initalarmtimespan; OneConfig. appsettings.settings["Alarmsecondstimeout"]. Value =Ivmbasic.acceptalarmtime; A  - CONFIG. Save (configurationsavemode.modified); -Configurationmanager.refreshsection ("appSettings");

2. Read the app. config file

Httpurl = configurationmanager.appsettings["Httpserviceurl"];

  

 

Read and write operations for configuration files (app. config)

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.