在WPF中读写config配置文件,很简单。
1. 在你的工程中,添加app.config文件。文件的内容默认为:
[csharp] view plaincopyprint?<?xml version="1.0" encoding="utf-8" ?> <configuration> </configuration>2.如果你想给程序配置一些参数,就在<monospace; white-space: pre;">configuration>标签中添加<appSettings>.例如: [html] view plaincopyprint?
<?xml version="1.0" encoding="utf-8" ?> <configuration> <appSettings> <add key="Path" value="SFSFSDSDS"/> <add key="NAME" value="FUCk"/> </appSettings> </configuration>3.然后你在程序里需要的地方读写它就可以了。先引用 [csharp] view plaincopyprint?
using System.Configuration;4.读: [csharp] view plaincopyprint?
string str = ConfigurationManager.AppSettings["Path"];5.写: [csharp] view plaincopyprint?
Configuration cfa = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None); cfa.AppSettings.Settings["NAME"].Value = "WANGLICHAO"; cfa.Save();6.收工!