Beispiel #1
0
        public void Save(string filename)
        {
            string folder = Path.GetDirectoryName(filename);

            if (!Directory.Exists(folder)) Directory.CreateDirectory(folder);

            XmlConverter xmlConverter = new XmlConverter();
            XmlDocument xmlDocument = new XmlDocument();

            xmlDocument.AppendChild(xmlDocument.CreateXmlDeclaration("1.0", null, null));

            ConversionContext context = new ConversionContext { Culture = Culture.Invariant, Device = xmlDocument };

            XmlNode xmlNode = xmlConverter.ConvertTo(this, context) as XmlNode;

            if (xmlNode != null)
            {
                xmlDocument.AppendChild(xmlNode);

                xmlDocument.Save(filename);
            }
        }