CMAB usage
CMAB use method 1. Create a new WinForm project Testa. 2. References Microsoft.ApplicationBlocks.configurationManagement.dll and Microsoft.ApplicationBlocks.configurationManagement.Interfaces.dll two class libraries. 3. Import Namespaces in the program Using Microsoft.ApplicationBlocks.configurationManagement; 4. Right-click on the project in the Solution Manager, Add-"Add a new item -" Application Profile ", name the newly added configuration file app.config Click Open Add Profile.
Add the following code in the configuration file after the addition is completed: XML Version = "1.0" encoding = "UTF-8"?>
(Namespace program loaded into the two classes below) [ComVisible (false)] public class CustomSectionHandler: IConfigurationSectionHandler, IConfigurationSectionHandlerWriter {XmlSerializer xs = new XmlSerializer (typeof (CustomConfigurationData)); public object Create (object parent, object hmm, XmlNode configSection) {object tmpObj = null; tmpObj = xs.Deserialize (new StringReader (configSection.OuterXml)); return (CustomConfigurationData) tmpObj;} public XmlNode Serialize (object value) {try {StringWriter sw = new StringWriter (System.Globalization. CultureInfo.CurrentUICulture); xs.Serialize (sw, value); XmlDocument doc = new XmlDocument (); doc.LoadXml (sw.ToString ()); return doc.ChildNodes [1];} catch (Exception e) {throw new ConfigurationException ("This configuration item cannot be serialized!", E);}}} 8. Add two text boxes on the form, two lable and two buttons fill in the name of the two lable text "Two" age " This box is named TXTNAME and TXTAGE. Change the name of Button1 to btnread, and the text property is changed to "Read". Button2's Name property is changed to btnWrite, and the text property is changed to "write". 9. btnRead click event which add the following code CustomConfigurationData cclass = (CustomConfigurationData) ConfigurationManager.Read ( "OtherConfigFile"); txtName.Text = cclass.name; txtAge.Text = cclass.age; 10. click of btnWrite add the following code in the event CustomConfigurationData cf = new CustomConfigurationData (); cf.name = txtName.Text.Trim (); cf.age = txtAge.Text.Trim (); ConfigurationManager.Write ( "OtherConfigFile", cf); the above The procedure can be read and write the configuration file after running the program.
If you use the encrypted set to true, you can achieve encrypted Xml version = "1.0" Encoding = "UTF-8"?>