[RESOLVED] How to get text from a text file and save it in the application?
So, here's the situation.
I first want my program to get the text from a text file(I know how that's done), but once it gets it, I want to somehow save it that it won't need to get the text again(for example, if you restart the application, it won't need to get the text from the file because the text is already saved). Can you please help me with this?
Re: How to get text from a text file and save it in the application?
Re: How to get text from a text file and save it in the application?
If an application wants to save data, it saves it to a file. You can save it to a different file if you want, e.g. a database (which is a file underneath) or the application config file, but it will still be a file of some sort. You can store data inside the EXE itself as a resource, but that is something that you do at compile time.
I would guess that your best bet would be to use an application setting. You create it on the Settings page at design time and you can then assign the text from the other file to the property of My.Settings in code. The value of the setting will then be saved automatically at shutdown and reloaded automatically at startup.
Re: How to get text from a text file and save it in the application?
Quote:
Originally Posted by
jmcilhinney
If an application wants to save data, it saves it to a file. You can save it to a different file if you want, e.g. a database (which is a file underneath) or the application config file, but it will still be a file of some sort. You can store data inside the EXE itself as a resource, but that is something that you do at compile time.
I would guess that your best bet would be to use an application setting. You create it on the Settings page at design time and you can then assign the text from the other file to the property of My.Settings in code. The value of the setting will then be saved automatically at shutdown and reloaded automatically at startup.
I partially get what you are saying, but I don't know how to do it. I have never worked with My.Settings before. :(
Re: How to get text from a text file and save it in the application?
Re: How to get text from a text file and save it in the application?
Go into Project|Properties and look at the Settings tab. You can add custom settings in there of various types.
Once you have added a setting to hold your information, you would access it for either reading or writing with:
My.Settings.<your setting name here>
It would act pretty much like a variable that is loaded every time your program starts. If you want to add a different number of strings each time, you can use the Specialized.StringCollection type, which would give you something akin to a List (of String).
Re: How to get text from a text file and save it in the application?
Re: How to get text from a text file and save it in the application?
Once you've added the setting to your app, all the code you need is basically:
vb.net Code:
My.Settings.SomeSetting = IO.File.ReadAllText("file path here")
Re: How to get text from a text file and save it in the application?
Quote:
Originally Posted by
jmcilhinney
Once you've added the setting to your app, all the code you need is basically:
vb.net Code:
My.Settings.SomeSetting = IO.File.ReadAllText("file path here")
Quote:
Originally Posted by HerkyBird
Tutorial here
Thanks guys! I will try this and post the results what happened. :)
Re: How to get text from a text file and save it in the application?
Thanks to all! I've solved my problem! :D:D:D