Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# Forms
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 30-Apr-13 0:58am
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

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.
  Permalink  
Comments
Modestas Krusa at 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 at 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.
Modestas Krusa at 30-Apr-13 8:32am
   
many thanks!
Owe you a beer now :)
OriginalGriff at 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:
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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[^]
  Permalink  

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

  Print Answers RSS
0 Marcin Kozub 330
1 OriginalGriff 256
2 Sergey Alexandrovich Kryukov 215
3 Praneet Nadkar 197
4 Richard MacCutchan 182
0 OriginalGriff 8,048
1 Sergey Alexandrovich Kryukov 7,287
2 DamithSL 5,614
3 Manas Bhardwaj 4,986
4 Maciej Los 4,910


Advertise | Privacy | Mobile
Web03 | 2.8.1411023.1 | Last Updated 30 Apr 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100