C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Communities   Interview   Jobs   Projects   Offshore Development    
Silverlight Tutorials | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Revenue Sharing |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...

New Feature: Community Sites: Create your own .NET community website and start earning from Google AdSense ! It's Free !




How to Serialize or Deserialize an object


Posted Date: 27 Mar 2008    Resource Type: Code Snippets    Category: C# Syntax

Posted By: Brij Bhushan Mishra       Member Level: Bronze
Rating:     Points: 7



When we create an object and store it in afile then i want ot send it across network so we need to convert it in a different format that is called Serialization and at the other end when it is converted again in the original format then it is called Deserailization.Please see the Code snippet.We can serialize an object using Binaryformatter or XMLformatter.Here I am using binary formatter



//SERAILIZATION

// Create file to save the data to
FileStream fs = new FileStream(@"C:\Date.Data", FileMode.Create);
BinaryFormatter bf = new BinaryFormatter();
// Use the BinaryFormatter object to serialize the data to the file
bf.Serialize(fs, System.DateTime.Now);
// Close the file
fs.Close();

//DESERAILIZATION

// Open file to read the data from
fs = new FileStream(@"C:\Date.Data", FileMode.Open);

DateTime data=new DateTime();
// Use the BinaryFormatter object to deserialize the data from the file
data = (DateTime)bf.Deserialize(fs);
// Close the file
fs.Close();
// Display the deserialized string
Console.WriteLine(data);






Responses


No responses found. Be the first to respond and make money from revenue sharing program.

Feedbacks      
Popular Tags   What are tags ?   Search Tags  
(No tags found.)

Post Feedback


This is a strictly moderated forum. Only approved messages will appear in the site. Please use 'Spell Check' in Google toolbar before you submit.
You must Sign In to post a response.
Next Resource: Add a column to DataTable from other Datatable of Different Database
Previous Resource: How to find size of an image?
Return to Discussion Resource Index
Post New Resource
Category: C# Syntax


Post resources and earn money!
 
Related Resources



dotNet Slackers   BizTalk Adaptors    Web Design

online optimum rewards

Contact Us    Privacy Policy    Terms Of Use