Solved:
the below method ObjectToXml take the obj and filename as the parameters and with the help of XmlSerializer it create the xml file on the given path
namespace Utility
{
public class Serial
{
public static void ObjectToXml(object obj, string path_to_xml)
{
try
{
if(File.Exists(path_to_xml))
File.Delete(path_to_xml);
XmlSerializer ser = new XmlSerializer(obj.GetType(),new XmlRootAttribute("document"));
FileStream fs = File.Open(
path_to_xml,
FileMode.OpenOrCreate,
FileAccess.Write,
FileShare.ReadWrite);
ser.Serialize(fs, obj);
fs.Close();
}
catch (Exception ex)
{
throw new Exception("Could Not Serialize the object to " + path_to_xml, ex);
}
}
}
}