POST 2: Storing text data in a file for program use
I posted about this issue already and I did receive some helpful info from people, but unfortunately my problem still isn't resolved.
Here is what I would like to do:
- Store string data from a 'sign in' form into a text file. This text file must be one that is saved even after the user exits the program. The text file must also be one that will stay with the program even after it is published (executable).
- Be able to write to/read from the file for purposes of displaying some or all of that data on a form.
When I posted before, a couple of people suggested I use an Application Setting to do this - of type 'Specialized String Collection'. I tried this, but for some reason I could not get it to work. It was a good idea, but I need to be able to SEE the data that has been saved, and with a setting it seems like that is not easily done. I've decided that I either need to use a simple text file or a 1-table database for this. I would prefer just a text file, but in either case, it needs to be part of the .exe when published.
I have added a text file to my project, but I am not sure if it will be "included" in the project when I publish it (forgive me, I am still an amateur at this). The path of the file I've added is in 'My Documents', but in my code, I will have to specify the path in order to use Streamwriter. How will this affect the program when I publish it??
I felt the need to make a new thread because on my last one we had been mainly talking about settings, and I've decided that isn't the best option for me.
I think I just need to be educated on project files and what exactly happens when a project is turned into an .exe. I would greatly appreciate any help that I can get! Thanks everyone, including the ones who tried to help me before!
Re: POST 2: Storing text data in a file for program use
Quote:
Originally Posted by
mk31369
I posted about this issue already and I did receive some helpful info from people, but unfortunately my problem still isn't resolved.
Here is what I would like to do:
- Store string data from a 'sign in' form into a text file. This text file must be one that is saved even after the user exits the program. The text file must also be one that will stay with the program even after it is published (executable).
- Be able to write to/read from the file for purposes of displaying some or all of that data on a form.
This is not a problem at all. Working with plain text for data storage gets awkward if the txt file size grows large, but for small files it's quite easy. One thing you should know about text files is that they are read/written continuously, so it's ok when you try to append something to the end of the file but inserting data in the middle will not be that easy.
Quote:
Originally Posted by
mk31369
When I posted before, a couple of people suggested I use an Application Setting to do this - of type 'Specialized String Collection'.
A .settings file is great for storing the app settings, indeed this is how your settings should be stored.
Quote:
Originally Posted by
mk31369
I tried this, but for some reason I could not get it to work. It was a good idea, but I need to be able to SEE the data that has been saved, and with a setting it seems like that is not easily done.
Perhaps, a bit more specific question about what exactly isn't working as it should be could help you to advance further.
Quote:
Originally Posted by
mk31369
I've decided that I either need to use a simple text file or a 1-table database for this. I would prefer just a text file, but in either case, it needs to be part of the .exe when published.
Now, this part in bold I don't quite understand. While you can embed a text file in your executable you will only be able to read from it, but not write to. Self-modifying executables died a long time ago, in times of MS-DOS. Now, once .exe is built - it doesn't change. Besides, you said, yo need to be able to SEE the data that has been saved and storing your data in an executable file is not the best way to do it.