XML configuration file:
XML Version = "1.0"?>
Implementation of operation:
Using system; using system.web; using system.text; using system.xml.serialization; using system.xml;
Namespace LTPTOOL {#Region Configuration Object Model Class
///
} #Endregion
#REGION configuration MODULECONFIG / / /
public static ModuleSettings GetSettings () {ModuleSettings data = null; XmlSerializer serializer = new XmlSerializer (typeof (ModuleSettings)); try {string fileName = "db.config"; FileStream fs = new FileStream (fileName, FileMode.Open); data = (ModuleSettings) serializer.Deserialize (fs); fs.Close ();} catch {data = new ModuleSettings ();} return data;} public static void SaveSettings (ModuleSettings data) {string fileName = "db.config"; XmlSerializer Serializer = new xmlserializer (typeof (modulesettings)); // serialize the object filestream fs = new filestream (filename, filemode.create); serializer.Serialize (fs, data); fs.close ();
#ndregion
}
}
Get detailed information on the configuration file;
ModuleSettingS settings = moduleconfig.get settings (); txtserver.text = settings.dataSource; txtuser.text = settings.uid; txtpass.text = settings.password;
Save changes:
Settings.datasource = txtserver.text; moduleconfig.savesettings (settings);
It is also very convenient for extended configurations, just modifying the modules of ModuleSettings and the file names in ModuleConfig. You can use any other configuration files.