Probably this may be very basic question but I’m working on a small example project for my understanding and I need some help here to finish this.
public class XMlExample : INotifyPropertyChanged
{
[XmlElement("ID")]
public string ID { get; set; } //Textbox
[XmlAttribute("Initial")]
public string Initial { get; set; } //Textbox
public event PropertyChangedEventHandler PropertyChanged;
}
public class Details //Datagrid
{
[XmlElement("FirstName")]
public string FirstName { get; set; }
[XmlElement("LastName")]
public string LastName { get; set; }
}
This is the in-completed function:
Read Write Function:
Button1 to read XML file:
XmlSerializer deserializer = new XmlSerializer(typeof(XMlExample));
TextReader textReader = new StreamReader(@"C:\test\testserialization.xml");
XMlExample xmlexmaple;
xmlexmaple = (XMlExample)deserializer.Deserialize(textReader);
textReader.Close();
Button 2 to write XML file:
XmlSerializer serializer = new XmlSerializer(typeof(XMlExample));
TextWriter textWriter = new StreamWriter(@"C:\test\testserialization.xml");
serializer.Serialize(textWriter, XXXX);
textWriter.Close();
Please somebody assist me that How can i get the values from textbox and datagrid to write as a xml file and how can i read that back to the interface. Thank you.
To serialize/deserialize the
Datagrid, you can add a property for it in yourXMLExampleClass and add theSerializableattribute to both classes.After deserializing, in your
Button1handler, you can populate your user interface controls appropriately. Before serializing the class, in yourButton2handler, you’ll need to populate the properties in your class appropriately.testserialization.xml