Click here to Skip to main content
15,888,802 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello Guys,
I was trying to find out a simple way of saving form data into some text file and reading from it, but.... could not find anything usefull... hopefully you can give me hand with this... which would be hihly appreciated:

I have a simple form with like 10 TetxBoxes. All I want to have is 2 additional buttons in the form. 1st for saving entered data into some txt or other file and 2nd to read from that file.

This is usefull when you fill half of the form and decide to finish later. Then you save it and next day you load and continue from there. I need to save TextBox values and values from DropDown lists.

Any link to resource or comment would be appreciated.

Thanks a lot again!

Modestas
Posted

This is actually pretty simple, assuming that your textboxes are all single line. (If they are multiline, it gets a little more complex as you probably need to convert them to a single string with separators, and split them back up again when you reload them)

There are a load of ways to do this.
1) You could just read and write from a text file - it's simple to do: just create a StreamWriter and write each string on a separate line. Then read them back line by line and reset you textboxes and so forth.
2) You could use applications settings - again it's simple, you add a setting in your application then access it vis Properties.Settings.Default.MySettingName for each line. Has the advantage over a text file that you can supply a default if the file is not initially present.
3) You could use an XMLDocument to serialise your data. A little more complex, but not a lot.
4) You could use a simple database (SQLCE or SQLite perhaps) to store and retirve your data.

There are other solutions (lot of them) but those are probably the simplest ones to implement.

It depends on what you want to store really, and how robust / human editable you want things to be.

For a really simple solution that didn't use file names, I'd probably go with option 2.
 
Share this answer
 
Comments
MK-Gii 30-Apr-13 7:11am    
Thanks for really great explanation.
The form that I build inserts the data into SQL server table and you know - I prefer for users to save the files locally on the disc (not use other DBs). The text can be long - multiple lines.
XML document looks the most attractive for me.... besides - any simple way to encrypt the data in that file? with C++ I have used binary coding.... but not sure if there is something good in C# (I hope it is) :)

Thanks a again OriinalGriff!
OriginalGriff 30-Apr-13 7:25am    
Binary coding is not an encryption method - it's just a data conversion! Have a look here:
http://msdn.microsoft.com/en-us/library/ms229746.aspx
It's about XML document encryption.
MK-Gii 30-Apr-13 8:32am    
many thanks!
Owe you a beer now :)
OriginalGriff 30-Apr-13 8:37am    
If I'm ever in the states again (or wherever you really are) I'll hold you to that! :laugh:
Quote:
I was trying to find out a simple way of saving form data into some text file and reading from it, but.... could not find anything usefull...

This simply isnt true: Google[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900