1. 程式人生 > >在WPF中讀寫config配置檔案

在WPF中讀寫config配置檔案

1. 在你的工程中,新增app.config檔案。檔案的內容預設為:
<?xml version="1.0" encoding="utf-8" ?>  
<configuration>  
</configuration>  
2.如果你想給程式配置一些引數,就在<configuration>標籤中新增<appSettings>.例如:
<?xml version="1.0" encoding="utf-8" ?>  
<configuration>  
  <appSettings>  
    <add key="Path" value="SFSFSDSDS"/>  
    <add key="NAME" value="FUCk"/>  
  </appSettings>  
</configuration>  
3.然後你在程式裡需要的地方讀寫它就可以了。先引用
using System.Configuration;  
4.讀:
string str = ConfigurationManager.AppSettings["Path"];  
5.寫:
Configuration cfa = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);  
cfa.AppSettings.Settings["NAME"].Value = "WANGLICHAO";