List of Class To XML File ,C#
if you create a collection class that have a list of Class Like :
public class Foo
{
public List BarList { get; set; }
}
public class Bar
{
public string Property1 { get; set; }
public string Property2 { get; set; }
}
we can use XmlSerializer to Save Collection to XML File
Foo f = new Foo();
f.BarList = new List();
f.BarList.Add(new Bar { Property1 = "abc", Property2 = "def" });
XmlSerializer ser = new XmlSerializer(typeof(Foo));
using (FileStream fs = new FileStream(@"c:\sertest.xml", FileMode.Create))
{
ser.Serialize(fs, f);
}
Comments
Post a Comment