I have this class:
public class MyMenu
{
public string Name { get; set; }
public string Type { get; set; }
}
This class I want to use it in a dynamic menu, and I do not want to store his data in a database.
I want to store its data in Xml
file.
Till now I have this for saving data:
string path = Server.MapPath("~/Content/Files");
XmlSerializer serial = new XmlSerializer(model.GetType());
System.IO.StreamWriter writer = new System.IO.StreamWriter(path + "\\ribbonmenu");
serial.Serialize(writer, model);
writer.Close();
And this to get the data:
string path = Server.MapPath("~/Content/Files");
XmlSerializer serial = new XmlSerializer(typeof(RibbonMenu));
System.IO.StreamReader reader = new System.IO.StreamReader(path + "\\ribbonmenu");
RibbonMenu menu =(RibbonMenu) serial.Deserialize(reader);
reader.Close();
What I have is working for one object to save and get. I need to save multiple objects, and get the collection of objects, something like:
IEnumerable<MyMenu> model=(IEnumerable<MyMenu>) serial.Deserialize(reader);
Can someone give me a solution? Thanks.
Edit: The content of the generated Xml with my code is:
<?xml version="1.0" encoding="utf-8"?>
<MyMenu xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<Id>0</Id>
<Menu>Home</Menu>
<Type>Button</Type>
</MyMenu>