Home Submit Snippets Cy2Online.Net  
Ads by Lake Quincy Media
 
 
 
View Snippet
C# XML Simple Write XmlSerializer
Viewed: 471
Date: 2009-04-08
This snippet shows how to serialize a class into XML using the XmlSerializer Class.
View Snippet
using System;
using System.IO;
using System.Xml.Serialization;
 
    class Program
    {
        static void Main(string[] args)
        {
            Product Item1 = new Product();
            Item1.Name = "Mp3 Player";
            Item1.Price = 33.99;
 
            FileStream fStream = new FileStream("product.xml", FileMode.Create);
            XmlSerializer xmlSerializer = new XmlSerializer(typeof(Product));
            xmlSerializer.Serialize(fStream, Item1);
            fStream.Close();
            Console.WriteLine("Item1 has been serialized");
            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
Check If User Is Administrator VB.Net Security 45
Encrypt Text Using TripleDESCryptoServiceProvider VB.Net Security 16
Hash Text Using SHA1Managed VB.Net Security 12
CrystalReportViewer Example VB.Net Controls 21
Drag Drop Image File Onto Form VB.Net Controls 35
Drag Drop A File Into TextBox VB.Net Controls 30
PrintPreviewControl Example VB.Net Controls 30
Nested DataRelation VB.Net Database 12
Play System Sound VB.Net Multimedia 31
Play Wav File VB.Net Multimedia 37
Semi Transparent Panel VB.Net Controls 31
Serialize Class To XML VB.Net File Manipulation 58
Get Hidden Files In Directory VB.Net File Manipulation 24
Simple PrintDocument Example VB.Net Controls 42
Reflection Example 1 VB.Net Miscellaneous 41
Insert Image Into RichTextBox VB.Net Controls 65
Show Image With Watermark VB.Net Graphics 41
Get Memory Information VB.Net File Manipulation 39
Get Runing Processes VB.Net Miscellaneous 33
FileSystemWatcher Example 1 VB.Net File Manipulation 45
DataTable To XML VB.Net Database 73
SqlDataReader To XML VB.Net Database 65
UDP File Transfer Example VB.Net Network 155
UDP Server Example VB.Net Network 75
UDP Client Example VB.Net Network 68
Read XML File From Web Server VB.Net Network 131
Get System Information VB.Net Miscellaneous 82
Get Windows Services VB.Net Miscellaneous 45
Get Cursor Position VB.Net Miscellaneous 68
Get Properties Of Current Thread VB.Net Miscellaneous 45
Time Difference Between Two Dates VB.Net Miscellaneous 51
Copy Image To Clipboard VB.Net Miscellaneous 193
Get Host Name By IP VB.Net Network 72
Get IP Address By Domain Name VB.Net Network 117
ListView Group Example VB.Net Controls 143
Add Items To ListView Using ListViewItem VB.Net Controls 131
Calculate Age MySQL - SQL Select 62
Get Drive Format VB.Net File Manipulation 64
Get Drive Info VB.Net File Manipulation 96
Query Access 2003 Database Using OleDbDataAdapter VB.Net Database 70
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.
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.
Connect To SQLServer - C#
This simple snippet creates a connection to an SQLServer.
Check If File Exists - C#
This snippet checks to see if a file exists using the FileInfo Class.
Get IP Address - C#
This code snippet will get the computers IP address.
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.
Get File Path - C#
TThis code snippet gets the filename and path of a selected file using the FileOpenDialog Class.
Simple Editable Table Columns - Javascript
This snippet allows you to edit the cells of a table.
Send Mail Using SmtpClient - C#
This is a very simple code snippet which demonstrates how to use the SmtpCleint Class to send outgoing mail.