|
WPF lees/schrijf configuratie bestandsblad. 1. Voeg in je project het app.config-bestand toe. De inhoud van het standaard bestand is: - <?xml version="1.0" encoding="utf-8" ?>
- <configuration>
- </configuration>
Code kopiëren
2. Als je enkele parameters voor het programma wilt configureren, <configuration>voeg ze dan toe aan de tag<appSettings>. Bijvoorbeeld, het volgende: - <?xml version="1.0" encoding="utf-8" ?>
- <configuration>
- <appSettings>
- <add key="Path" value="D:"/>
- <add key="NAME" value="123"/>
- </appSettings>
- </configuration>
Code kopiëren3. Dan kun je het lezen en schrijven waar je het nodig hebt in het achtergrondprogramma. Vergeet niet om bronvermeldingen toe te voegen
gebruikmakend van System.Configuration; 4. Lees de operatie:
string strPath = ConfigurationManager.AppSettings["Path"]; 5. Schrijf operaties:
Configuration cfa = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None); CFA. AppSettings.Settings["NAME"]. Waarde = "WANGLICHAO"; CFA. Save();
|