473,395 Members | 1,454 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Saving Custom Data

In the past, using either C++ or VB (classic), I routinely stored records of
data as an array of structures, and then simply read and wrote them to and
from a file using basic file operations.

So now I'd like to do something similar with my first .NET application but I
really don't know where to start. I do not feel a database or XML file is
appropriate for this data. I simply want to read and write it to and from a
file in the most efficient manner.

Can anyone offer any examples or tips? Specifically, the questions that are
coming up include:

1. Should I still use structures or am I better off accepting any additional
overhead of using class objects to represent each record?
2. What is the best way to write structures or classes to disk?
3. What is the best way to write a collection of structures or classes to
disk?
4. How come most of the file and try...catch examples I've found seem
absolutely retarded to me? For example, most leave the line that opens the
file (the line most likely to fail) before try, outside of the try block?
What is the point of that?

Thanks.

--
Jonathan Wood
SoftCircuits Programming
http://www.softcircuits.com

Jul 14 '07 #1
1 1156
"Jonathan Wood" <jw***@softcircuits.comwrote in message
news:%2****************@TK2MSFTNGP04.phx.gbl...
1. Should I still use structures or am I better off accepting any
additional overhead of using class objects to represent each record?
I don't think that there's any difference at the time of writing them to
disk. You should choose structures or classes based on how you are going to
use them in your program, not on the need of writing to disk.
2. What is the best way to write structures or classes to disk?
My favourite way is to serialize them. Mark the class or struct with a
[Serializable] attribute and then use a BinaryFormatter to write the
contents to a FileStream.
3. What is the best way to write a collection of structures or classes to
disk?
Make sure that all the objects in the collection are [Serializable] and
apply the preceding method.
4. How come most of the file and try...catch examples I've found seem
absolutely retarded to me? For example, most leave the line that opens the
file (the line most likely to fail) before try, outside of the try block?
What is the point of that?
Maybe they do that because they are writing a Finally block that is
closing the file, so they only want it to execute if the open succeeded. If
it fails, it is caught at a higher level (a try...catch in the routine that
made the call to the ne that is opening the file). I'm not saying that I
like this, just trying to find a logic for the examples that are written in
the way you mention.

Jul 14 '07 #2

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

Similar topics

138
by: theodp | last post by:
--> From http://www.techdirt.com/articles/20040406/1349225.shtml Microsoft Patents Saving The Name Of A Game Contributed by Mike on Tuesday, April 6th, 2004 @ 01:49PM from the...
5
by: Michael Albanese | last post by:
Can you save objects a (custom class) to Viewstate and then get them on a later page?? I have a custom class for an ASP.Net application that I would like to make available across several web...
4
by: John Kandell | last post by:
Hi, I posted this in the asp.net group, but didn't get a response. Maybe someone here can help me with this... --- Would someone be able to shed some light on what is the cost of saving a...
2
by: Jay Walker | last post by:
I created a custom DataGridColumn based on Marcie Robillard's MSDN Article: Creating Custom Columns for the ASP.NET Datagrid...
2
by: RA | last post by:
Hi I use ASP.net with c#. The web application is hosted by a web host provider. The application gets user information for order processing. The information should be moved from one aspx page to...
6
by: catherine.bajis | last post by:
I have a small project to create some simple HTML forms. Rather than have our users go to our web page and 'SUBMIT' the form data, it would be easier for them to fill out a simple standalone form,...
4
by: Pedro Leite | last post by:
Good Afternoon. the code below is properly retreiving binary data from a database and saving it. but instead of saving at client machine is saving at the server machine. what is wrong with my...
1
by: VMI | last post by:
I'm working on a web application that's basically a questionaire that consists of 8 pages. Each page has different data that needs to be saved. I have to either save all the data from all 8 pages...
3
by: Nathan Guill | last post by:
I have an interface that works with an Access back-end. I would like to store and/or load user defined query strings per each user (i.e. no user can access another's queries). The idea I had was...
18
by: Marilyth | last post by:
I am using Windows XP and Access 2003. I have searched through my HUGE book & the questions here, and found some items that "might" help, but unsure still. I am still getting versed on Access. I...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
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...

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.