public void CreateXML(Template template)
        {
            XmlDocument xmlDoc = new XmlDocument();   //Represents an XML document,
                                                      // Initializes a new instance of the XmlDocument class.
            XmlSerializer xmlSerializer = new XmlSerializer(template.GetType());
            // Creates a stream whose backing store is memory.

            string XMLString = String.Empty;
            using (MemoryStream xmlStream = new MemoryStream())
            {
                xmlSerializer.Serialize(xmlStream, template);
                xmlStream.Position = 0;
                //Loads the XML document from the specified string.
                xmlDoc.Load(xmlStream);
                XMLString =  xmlDoc.InnerXml;
            }

            // create an xml file
            string templatefilepath = TemplateAbsolutePath + TemplateFileName;
            Directory.CreateDirectory(TemplateAbsolutePath);
            FileStream stream = File.Open(templatefilepath, FileMode.OpenOrCreate);
            byte[] data = new UTF8Encoding(false).GetBytes(XMLString);
            stream.Write(data, 0, data.Length);

            stream.Close();
            stream.Dispose();
        }
 public Template LoadTemplateFromFile(string XMLfile, Template template)
 {
     XmlSerializer oXmlSerializer = new XmlSerializer(template.GetType());
     //The StringReader will be the stream holder for the existing XML file
     string XMLString  = File.ReadAllText(XMLfile);
     template = (Template) oXmlSerializer.Deserialize(new StringReader(XMLString));
     //initially deserialized, the data is represented by an object without a defined type
     return template;
 }