Serialize the object to xml file - CSharp System.Xml

CSharp examples for System.Xml:XML Serialization

Description

Serialize the object to xml file

Demo Code

//  Licensed under the GPLv2: http://dotnetage.codeplex.com/license
using System.Xml.Serialization;
using System.Xml;
using System.IO;/* w  w w  .  j a v  a2 s.com*/
using System;

public class Main{
        public static void SerializeToXmlFile<T>(string fileName, T instance)
        {
            SerializeToXmlFile(fileName, typeof(T), instance);
        }
        /// <summary>
        /// Serialize the object to xml file
        /// </summary>
        /// <param name="fileName"></param>
        /// <param name="type"></param>
        /// <param name="instance"></param>
      public static void SerializeToXmlFile(string fileName, Type type, object instance)
      {
         FileStream stream = new FileStream(fileName, FileMode.OpenOrCreate, FileAccess.Write, FileShare.Write);
            SerizlizeToStream(stream,type,instance);
           stream.Close();
      }
}

Related Tutorials