Technisches‎ > ‎

How to save a business object as a file and reload it again (Serialization)

using System.Xml.Serialization;

using System.IO;


public class Serialisierung


    public static void SaveXML(object obj, string pfad)


        FileStream myStream = new FileStream(pfad, FileMode.Create);

        new XmlSerializer(obj.GetType()).Serialize(myStream, obj);



    public static object OpenXML(string pfad, Type t)


        FileStream fs = new FileStream(pfad, FileMode.Open);

        return new XmlSerializer(t).Deserialize(fs);