refer
XmlSerializer Class (System.Xml.Serialization)[
^] class
follow the steps
Create an entity with the properties in the form as
public class MyEntity
{
public string Name { get; set; }
public string Age { get; set; }
public string Address { get; set; }
}
the below code is for using Asp.net application, however the concept is same for mvc or window etc..
protected void btnSave_Click(object sender, EventArgs e)
{
string filePath = Server.MapPath("xmlfiles") + "//" + "myfile.xml";
MyEntity entity = new MyEntity();
entity.Name = txtName.Text;
entity.Age = txtAge.Text;
entity.Address = txtAddress.Text;
XmlSerializer xs = new XmlSerializer(typeof(MyEntity));
TextWriter tw = new StreamWriter(filePath);
xs.Serialize(tw, entity);
}