Knowledge Management Banner

Knowledge Management Banner

Xml File To Object

//Required Libraries
using System.Xml.Serialization;
using System.IO;

public static T XMLFileToObject<T>(string Path) where T : class
{
    if (!File.Exists(Path))
        return null;

    XmlSerializer sr = new XmlSerializer(typeof(T));
    using (FileStream fileStream = new FileStream(Path, FileMode.Open, FileAccess.Read))
    {
        var result = sr.Deserialize(fileStream) as T;
        return result;
    }
}

No comments

Powered by Blogger.