How to serialize object in asp.net XML

XML Serialization - Serialize object
UsingSerialization.aspx

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

<!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\BookType.xml";
        BookType bookTypeObj = new BookType();
        bookTypeObj.BookTypeID = 1;
        bookTypeObj.BookTypeName = "asp.net";
        XmlSerializer serializer = new XmlSerializer(typeof(BookType));
        TextWriter writer = new StreamWriter(xmlPath);
        serializer.Serialize(writer, bookTypeObj);
        writer.Close();
        Label1.Text = "Xml document created successfully!";
    }
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
    <title>XML Serialization - How to serialize object in asp.net</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <h2 style="color:DarkBlue; font-style:italic;">XML Serialization Example: How To Serialize Objects</h2>
        <hr width="550" align="left" color="DarkBlue" />
        <asp:Label 
            ID="Label1" 
            runat="server"
            Font-Bold="true"
            Text=""
            Font-Size="X-Large"
            Font-Names="Comic Sans MS"
            ForeColor="DarkSalmon"
            >
        </asp:Label>
        <br /><br />
        <asp:Button 
            ID="Button1"
            runat="server"
            OnClick="Button1_Click"
            Text="Serialize Object and Create XML Document"
            Height="40"
            Font-Bold="true"
            ForeColor="DarkBlue"
            />
    </div>
    </form>
</body>
</html>
BookType.cs

using System;
[Serializable]
public class BookType
{
    public long BookTypeID;
    public string BookTypeName;
}
Related asp.net example