DNK Gif

Dot Net Knowledge

Labels

Tuesday, 21 July 2015

How to Read Object Data from an XML File using C#

Reading Object Data from an XML File using C#

This example reads object data that was previously written to an XML file using the XmlSerializer class.

public class Book
{
        public String title{get; set;};
}

public void ReadXML()
{
System.Xml.Serialization.XmlSerializer reader =
new System.Xml.Serialization.XmlSerializer(typeof(Book));

System.IO.StreamReader file = new System.IO.StreamReader(
@"c:\temp\SerializationOverview.xml");

Book overview = new Book();

overview = (Book)reader.Deserialize(file);

Console.WriteLine(overview.title);
}

Note:- 

By using this method only simple ViewModel data can be read,

No comments:

Post a Comment