Serialize To Xml File - CSharp System.Xml

CSharp examples for System.Xml:XML Serialization

Description

Serialize To Xml File

Demo Code


using System.Xml.Serialization;
using System.Xml;
using System.Text;
using System.IO;//w w  w  . ja v a 2 s.c  o m
using System;

public class Main{
        /// <summary>
        /// 
        /// </summary>
        /// <param name="filePath"></param>
        /// <param name="obj"></param>
        public static void SerializeToXmlFile(string filePath, object obj)
        {
            var writer = new StreamWriter(filePath);
            var xmlSerial = new XmlSerializer(obj.GetType());
            xmlSerial.Serialize(writer, obj);
            writer.Close();
        }
}

Related Tutorials