I try the following code to serialize my objects into xml file, but when run this code the last item in the list values
serialize by the count for the list.
I want to serialize every item in the list? what is the wrong in my code
Can anyone help me ?
//list of class values
List<values> valus = new List<values>();
values value = new values();
foreach (Control control in Controls)
{
value.ctrlname = control.Name.ToString();
value.ctrllocation = control.Location.ToString();
value.ctrltext = control.Text.ToString();
value.ctrltype = control.GetType().ToString();
value.ctrlstatus = control.Enabled.ToString();
valus.Add(value);
}
System.Xml.Serialization.XmlSerializer writer =
new System.Xml.Serialization.XmlSerializer(typeof(values));
var path = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "//Serialization.xml";
System.IO.FileStream file = System.IO.File.Create(path);
foreach (values item in valus)
{
writer.Serialize(file, item);
}
file.Close();