473,480 Members | 1,799 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Serialize class instance to file, then retrieve

I'd like to take an instance of a class, and serialize it to a file on my
computer. No security required on the file. Then, I'd like to be able to
unserialize the file later and use the instance again. A quick sample on
how to do this would be grand. A little pseudo code below just to clarify
what type of class I'd like serialize to a file ...

Thanks in advance.

Mark

[Serializable]
public class Person
{
private string _firstName;

public Person(firstName)
{
_firstName = firstName;
}

public string FirstName
{
get { return _firstName; }
}
}
Nov 16 '05 #1
1 1611
Just kidding. Just found a great example in the VS.NET help files under
".NET Framework Developer's Guide". The "Basic Serialization" section has a
full example of both.

"Mark" <fi******@idonotlikejunkmail.umn.edu> wrote in message
news:O2**************@TK2MSFTNGP15.phx.gbl...
I'd like to take an instance of a class, and serialize it to a file on my
computer. No security required on the file. Then, I'd like to be able to
unserialize the file later and use the instance again. A quick sample on
how to do this would be grand. A little pseudo code below just to clarify
what type of class I'd like serialize to a file ...

Thanks in advance.

Mark

[Serializable]
public class Person
{
private string _firstName;

public Person(firstName)
{
_firstName = firstName;
}

public string FirstName
{
get { return _firstName; }
}
}

Nov 16 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
5804
by: Ian Tompsett | last post by:
H I was wondering if it possible for an object to serialize/deserialize itself from XML. I'd be guessing that it would need to use the XmlSerializer class, but that seems to want to create a...
0
4497
by: jr | last post by:
Hello, I have got a schema file "myschema.xsd" from my customer for which I must create xml files. I used xsd.exe to create a class for the schema. I fill an object for that class with data...
1
2929
by: Michael | last post by:
Hi I anyone have a clue or can solve my problem I would be glad :-) Regards Michael I have a problem with creating an XML-document where the returning data from the webservice, have been...
5
24655
by: David Sworder | last post by:
Hi, I've created a UserControl-derived class called MyUserControl that is able to persist and subsequently reload its state. It exposes two methods as follows: public void Serialize(Stream...
10
4119
by: Dan | last post by:
All I Am Attempting To Serialize An Object To An XML File. Here Is The Code For That public string SaveNewSurvey( MutualSurveyObject mso_TempObject, int i_JobID ) { string s_RootFileName;...
5
2115
by: Arjen | last post by:
Hello, I have an array "aPeople" with people objects which I serialize like this: XmlSerializer x = new XmlSerializer( typeof(People) ); TextWriter writer = new StreamWriter( "data.xml" );...
7
3519
by: Ben Amada | last post by:
I've created a class that I need to store in ViewState. However when I try to store it in ViewState, I get the following error: "The type 'solution.pe2' must be marked as Serializable or have a...
4
7071
by: =?Utf-8?B?Qnlyb24=?= | last post by:
When I try to serialize an instance of the LocationCell below (note Building field) I get an error in the reflection attempt. If I remove the _Building field it serializes fine. I tried renaming...
3
10213
by: Julie | last post by:
Here's the scenario (public attributes, etc. omitted for brevity): class Base { } class Derived : Base { }
0
7040
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7080
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
6736
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
5331
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
4772
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4478
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
2980
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
561
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
178
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.