ASP.NET - How to deserialize xml document into an object

XML Deserialization - Deserialize xml document into an object
XMLDeserialization.aspx

<%@ Page Language="C#" AutoEventWireup="true" %>
<%@ Import Namespace="System.IO" %>
<%@ Import Namespace="System.Xml.Serialization" %>
<%@ Import Namespace="System.Drawing" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
    void Button1_Click(object sender, System.EventArgs e)
    {
        string xmlPath = Request.PhysicalApplicationPath + @"App_Data\Books.xml";
        Books booksObj = new Books();
        booksObj.bookid = 1;
        booksObj.bookname = "Professional Twitter Development: With Examples in .NET 3.5";
        booksObj.author = "Daniel Crenna";
        XmlSerializer serializer = new XmlSerializer(typeof(Books));
        TextWriter writer = new StreamWriter(xmlPath);
        serializer.Serialize(writer, booksObj);
        writer.Close();
        Label1.ForeColor = Color.DodgerBlue;
        Label1.Text = "Xml document created successfully!";
    }

    void Button2_Click(object sender, System.EventArgs e)
    { 
        string xmlFilePath = Request.PhysicalApplicationPath + @"App_Data\Books.xml";
        if(File.Exists(xmlFilePath))
        {
            XmlSerializer serializer = new XmlSerializer(typeof(Books));
            TextReader reader = new StreamReader(xmlFilePath);
            Books booksObj = (Books)serializer.Deserialize(reader);
            reader.Close();
            Label1.ForeColor = Color.OrangeRed;
            Label1.Text = "Book ID: " + booksObj.bookid.ToString();
            Label1.Text += "<br/>Name: " + booksObj.bookname.ToString();
            Label1.Text += "<br />Author: " + booksObj.author.ToString();
        }
        else
        {
            Label1.Text ="XML document not found";
            Label1.ForeColor = Color.Red;
        }
        
    }
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
    <title>XML Deserialization - How to deserialize xml document into an object</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <h2 style="color:DarkBlue; font-style:italic;">XML Deserialization Example: Deserialize xml document into an object</h2>
        <hr width="550" align="left" color="CornFlowerBlue" />
        <br /><br />
        <asp:Label 
            ID="Label1" 
            runat="server"
            Font-Bold="true"
            Text=""
            Font-Size="Large"
            Font-Names="Comic Sans MS"
            ForeColor="OrangeRed"
            >
        </asp:Label>
        <br /><br /><br />
        <asp:Button 
            ID="Button1"
            runat="server"
            OnClick="Button1_Click"
            Text="Serialize Object and Create XML Document"
            Height="40"
            Font-Bold="true"
            ForeColor="SeaGreen"
            />
        <asp:Button 
            ID="Button2"
            runat="server"
            OnClick="Button2_Click"
            Text="Deserialize XML Document"
            Height="40"
            Font-Bold="true"
            ForeColor="SeaGreen"
            />
    </div>
    </form>
</body>
</html>
Books.cs

using System;
[Serializable]
public class Books
{
    public int bookid;
    public string bookname;
    public string author;
}
Related asp.net example