|
WPF read/write config file sheet. 1. In your project, add the app.config file. The contents of the file default are: - <?xml version="1.0" encoding="utf-8" ?>
- <configuration>
- </configuration>
Copy code
2. If you want to configure some parameters for the program, <configuration>add them in the tag<appSettings>. For example, the following: - <?xml version="1.0" encoding="utf-8" ?>
- <configuration>
- <appSettings>
- <add key="Path" value="D:"/>
- <add key="NAME" value="123"/>
- </appSettings>
- </configuration>
Copy code3. Then you can read and write it where you need it in the background program. Remember to add citations
using System.Configuration; 4. Read operation:
string strPath = ConfigurationManager.AppSettings["Path"]; 5. Write Operations:
Configuration cfa = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None); cfa. AppSettings.Settings["NAME"]. Value = "WANGLICHAO"; cfa. Save();
|