Vijay

Vijay

  • NA
  • 150
  • 90.6k

Serialization&Deserialization

Jul 25 2013 1:36 AM
        
       I did program for xml serialization but i get error on this pgm.... plz clear my bug...
        
        
        public class Orders
        {
            public Book[] Books;
        }
       
        public class Book
        {
            //[XmlElement("Newbooooook", typeof(ExpandedBook))]
            public string ISBN;
            public string BookName;
        }
        
        public class ExpandedBook : Book
        {
           
            public bool NewEdition;
        }

        private void Serialize_Click(object sender, EventArgs e)
        {
            
            XmlSerializer seer =new XmlSerializer(typeof(Orders));            
            TextWriter writer = new StreamWriter(@"d:\xmlarra.xml");
           
            Orders myOrders = new Orders();
            
            ExpandedBook b = new ExpandedBook();
            b.BookID= txtid.Text;
            b.BookName = txtname.Text;
            b.NewEdition = bool.Parse(txtbool.Text);
            myOrders.Books = new ExpandedBook[] { b };

            // Serializes the object.
            seer.Serialize(writer, b);
            writer.Close();
        }
        private void txtbool_SelectedIndexChanged(object sender, EventArgs e)
        {
            ComboBox cb = (ComboBox)sender;
            if (!cb.Focused)
            {
                return;
            }
        }

Answers (3)