public static void ObjectToXml(object obj, string path_to_xml)
{
//serialize and persist it to it's file
try
{
System.Xml.Serialization.XmlSerializer writer =
new System.Xml.Serialization.XmlSerializer(obj.GetType());
System.IO.StreamWriter file =
new System.IO.StreamWriter(path_to_xml);
writer.Serialize(file, obj);
file.Close();
//XmlSerializer ser = new XmlSerializer(obj.GetType());
//FileStream fs = File.Open(
// path_to_xml,
// FileMode.OpenOrCreate,
// FileAccess.Write,
// FileShare.ReadWrite);
//ser.Serialize(fs, obj);
}
catch (Exception ex)
{
throw new Exception(
"Could Not Serialize object to " + path_to_xml,
ex);
}
}
{
//serialize and persist it to it's file
try
{
System.Xml.Serialization.XmlSerializer writer =
new System.Xml.Serialization.XmlSerializer(obj.GetType());
System.IO.StreamWriter file =
new System.IO.StreamWriter(path_to_xml);
writer.Serialize(file, obj);
file.Close();
//XmlSerializer ser = new XmlSerializer(obj.GetType());
//FileStream fs = File.Open(
// path_to_xml,
// FileMode.OpenOrCreate,
// FileAccess.Write,
// FileShare.ReadWrite);
//ser.Serialize(fs, obj);
}
catch (Exception ex)
{
throw new Exception(
"Could Not Serialize object to " + path_to_xml,
ex);
}
}
Comments
Post a Comment