Home Submit Snippets Cy2Online.Net  
Ads by Lake Quincy Media
 
 
 
View Snippet
C# XML Simple Read XmlSerializer
Viewed: 573
Date: 2009-04-08
This snippet shows how to read a serialized XML file using the XmlSerializer Class.
View Snippet
using System;
using System.IO;
using System.Xml.Serialization;
 
    class Program
    {
        static void Main(string[] args)
        {
            Product Item1;
 
 
            FileStream fStream = new FileStream("product.xml", FileMode.Open);
            XmlSerializer xmlSerializer = new XmlSerializer(typeof(Product));
            Item1 = (Product)xmlSerializer.Deserialize(fStream);
            Console.WriteLine("Item1: Name:" + Item1.Name);
            Console.WriteLine("Item1: Price:" + Item1.Price);
            fStream.Close();
            Console.ReadKey();
        }
    }
 
 
    [System.Xml.Serialization.XmlRootAttribute()]
    public class Product
    {
        private string name;
        private double price;
 
        [XmlElement("Name")]
        public string Name
        {
            set { this.name = value; }
            get { return name; }
        }
 
        [XmlElement("Price")]
        public double Price
        {
            set { this.price = value; }
            get { return price; }
        }
 
    }
 
 
New Snippets
Title Language Category Views
Edit TreeNode Example 1 C# Controls 336
Multiple Insert With One Query SQL - MySQL Insert 134
Read Image File As Bytes Visual C++ File Manipulation 149
TcpClient PortScanner Visual C++ Network 72
TcpClient Example Visual C++ Network 103
Managed And Unmanaged Example Visual C++ Miscellaneous 66
XmlDocument Example Visual C++ XML 109
Reading A CSV File Visual C++ File Manipulation 145
StreamWriter Example Visual C++ File Manipulation 146
StreamReader Example Visual C++ File Manipulation 170
Edit GridView And Save Changes ASP.Net - C# Controls 248
GridView From DataTable ASP.Net - C# Controls 205
Radial Gradient Circle Example 2 VB.Net Graphics 138
Radial Gradient Circle Example 1 VB.Net Graphics 135
Check If User Is Administrator VB.Net Security 206
Encrypt Text Using TripleDESCryptoServiceProvider VB.Net Security 133
Hash Text Using SHA1Managed VB.Net Security 112
CrystalReportViewer Example VB.Net Controls 208
Drag Drop Image File Onto Form VB.Net Controls 206
Drag Drop A File Into TextBox VB.Net Controls 208
PrintPreviewControl Example VB.Net Controls 259
Nested DataRelation VB.Net Database 86
Play System Sound VB.Net Multimedia 148
Play Wav File VB.Net Multimedia 134
Semi Transparent Panel VB.Net Controls 193
Serialize Class To XML VB.Net File Manipulation 173
Get Hidden Files In Directory VB.Net File Manipulation 129
Simple PrintDocument Example VB.Net Controls 341
Reflection Example 1 VB.Net Miscellaneous 116
Insert Image Into RichTextBox VB.Net Controls 343
Show Image With Watermark VB.Net Graphics 156
Get Memory Information VB.Net File Manipulation 152
Get Runing Processes VB.Net Miscellaneous 95
FileSystemWatcher Example 1 VB.Net File Manipulation 178
DataTable To XML VB.Net Database 174
SqlDataReader To XML VB.Net Database 197
UDP File Transfer Example VB.Net Network 331
UDP Server Example VB.Net Network 282
UDP Client Example VB.Net Network 234
Read XML File From Web Server VB.Net Network 337
Ads by Lake Quincy Media
Top Snippets
Semi Transparent Panel - C#
This snippet shows how to develop a custom panel which is semi transparent by overriding CreateParams and the OnPaint method of the Panel control.
Get File Path - C#
TThis code snippet gets the filename and path of a selected file using the FileOpenDialog Class.
Add Items To ListView Control - C#
This snippet adds items to a listview control. It loops through the files in the C:\ drive and displays the filename in the listview control.
Encrypt Text Using TripleDESCryptoServiceProvider - C#
This snippet uses the TripleDESCryptoServiceProvider Class to encrypt a string and save it to a text file. The key to decrypt the file is also saved into a seperate text file.
Read Image File As bytes - C#
This sinppet opens an image for reading as bytes. The bytes are then placed into a memorystream which is used to create a bitmap image of the bytes. The image is then set as the forms background image.
Check If File Exists - C#
This snippet checks to see if a file exists using the FileInfo Class.
Get Filename Using OpenFileDialog - C#
This code snippet gets the filename of a selected file from the Open File Dialog and displays it in a message box.
Get IP Address - C#
This code snippet will get the computers IP address.
Connect To SQLServer - C#
This simple snippet creates a connection to an SQLServer.
Simple Editable Table Columns - Javascript
This snippet allows you to edit the cells of a table.