save txt set in textbox's to INI file (form close) & load text from INI on form load?
So I've got a form with about 7-8 textbox's & i change the data in each like once every 3-4 days. It's a pain filling it all out each time.
So when I close the program, I'd like to save the current data (in each textbox on the form) to a INI file (In the root of whatever current folder I'm running it from)
Then when I load the program the next time, it will load the settings from the INI file to fill my textbox's back up.
Is there a simple way to add this to my program without major changes to my code?
Thanks for any suggestions/code/help!
I know this is kind of day 1 stuff for most programmers. But I had to just jump in running so I missed a lot of the basics!
Re: save txt set in textbox's to INI file (form close) & load text from INI on form l
You can setup each TextBox via the property windows, application ->ApplicationSettings ->PropertyBinding->Text, select new, provide a name. The file will be under App Data\Local i.e. on my Vista machine it would be C:\Users\kevininstructor\AppData\Local\WindowsApplication1 in User.config (it will be one level down from the sample path).
Re: save txt set in textbox's to INI file (form close) & load text from INI on form l
Quote:
Originally Posted by
kevininstructor
You can setup each TextBox via the property windows, application ->ApplicationSettings ->PropertyBinding->Text, select new, provide a name. The file will be under App Data\Local i.e. on my Vista machine it would be C:\Users\kevininstructor\AppData\Local\WindowsApplication1 in User.config (it will be one level down from the sample path).
Yup I just now found a forum post explaining application settings. But like when I've compiled the application & running it on different computers...in different folders etc. Is it going to work then? How do I tell the program to find the config file in the 'same folder' as the program. So then I can just zip up the config & distribute it along with the exe. So like If i give the program to someone else to use...they would run the program in... /desktop/new folder/program.exe & have the User.config in that same folder...which would save their very own settings after it's edited once by them. Or does this only work if you're config is in that 1 location...I'm kinda sorta confused now
It seems like for a portable application, that I will be using on several different pc's, or giving to friends...it would make more sense to use a config.ini wouldn't it?
I mean I'd be cool with saving it to/reading it from a normal text file....or a xml file...or even the registry
Re: save txt set in textbox's to INI file (form close) & load text from INI on form l
So is it possible to make the built-in application setting config file portable, so that It can be installed on other PC's, or at least different 'windows logins' on the same PC?
I.E. can u change the root directory of where it looks for the application setting config file?
1 Attachment(s)
Re: save txt set in textbox's to INI file (form close) & load text from INI on form l
Quote:
Originally Posted by
jalexander
Yup I just now found a forum post explaining application settings. But like when I've compiled the application & running it on different computers...in different folders etc. Is it going to work then? How do I tell the program to find the config file in the 'same folder' as the program. So then I can just zip up the config & distribute it along with the exe. So like If i give the program to someone else to use...they would run the program in... /desktop/new folder/program.exe & have the User.config in that same folder...which would save their very own settings after it's edited once by them. Or does this only work if you're config is in that 1 location...I'm kinda sorta confused now
It seems like for a portable application, that I will be using on several different pc's, or giving to friends...it would make more sense to use a config.ini wouldn't it?
I mean I'd be cool with saving it to/reading it from a normal text file....or a xml file...or even the registry
Hello,
First off I would not have suggested using this method had you indicated a portable application which never crossed my mind as I would say 99.99% of applications are designed not portable. If you want portable than sure you could use an INI file but that is outdated and require the use of specific API functions. One method that will work is using a xml file located (for you) in the same folder as the main assembly folder. I have attached a VS2008 project I did a while back, converted it just now and tested it to VS2010, Framework 4.
In the attached project the file below saves two check box controls check state and the text property of a TextBox when closing the form, reads the values in at start up and sets the controls.
Note: In the future always provide complete details to what you want which will get you better replies.
Code:
<?xml version="1.0" encoding="utf-8"?>
<UserSettings>
<FormControls>
<Form Name="Form1">
<CheckBox Name="CheckBox1" Checked="False" />
<CheckBox Name="CheckBox2" Checked="True" />
<TextBox Name="TextBox1" Text="Testing" />
</Form>
</FormControls>
</UserSettings>
Re: save txt set in textbox's to INI file (form close) & load text from INI on form l
If you really want to use INI files, you can scrap an API call and use a managed library instead.