|
-
Dec 25th, 2018, 05:53 PM
#1
Thread Starter
Lively Member
[RESOLVED] Carrying My.Settings (Config File)
My program I am working on depends on the my.settings to store information and then retrieve it back when the program starts up. My.settings from my understanding is stored in a configuration file locally on each computer. This creates a huge issue for me because my program is to be used on a flash drive from computer to computer by the same user. The issue is that the my.settings are reset anytime the user changes or the computer changes. I need a work around to where, if possible, to keep using my.settings and store the config file within the application path and open the same config file nomatter the user or computer. I am open to all ideas and any help would be apprecaited.
-
Dec 25th, 2018, 07:41 PM
#2
Re: Carrying My.Settings (Config File)
Any settings with Application scope are read-only via My.Settings and are stored in the main application config file, which is stored in the same folder as the EXE. Default values for settings with User scope are also stored in the main config file with the current values stored for each Windows user under that user's personal folder. You can't really do anything about that because they have to be stored per user in order to provide different values per user.
One option for you may be to handle the Shutdown event of your application and save all the current values for the User-scoped settings to a text file in the program folder. If your app is installed to Program Files then that may not be possible for a non-admin user but there will probably be no issues saving to a flash drive. You can then also handle the Startup event and look for that file, loading the values into My.Settings if you find it.
-
Dec 25th, 2018, 07:46 PM
#3
Re: Carrying My.Settings (Config File)
I was going to provide an example of what I suggested above but then I started to think that there probably wasn't much point. If you were going to do as I suggested then you wouldn't really be getting much - if any - benefit from using My.Settings in the first place. You probably may as well just store your own settings in your own file and save and load from there every time.
-
Dec 25th, 2018, 09:30 PM
#4
Thread Starter
Lively Member
Re: Carrying My.Settings (Config File)
Right, that was what I was thinking as well. The conveniency of being able to use the user / application settings is nice, however, it does not provide what I need in this case which is dissapointing. Even more so because I relied on it after I typed up my entire program. Which is the reason why I was hoping for a work around. Thanks for your help!
-
Dec 25th, 2018, 09:42 PM
#5
Re: [RESOLVED] Carrying My.Settings (Config File)
Another option would be to use My.Settings but only use Application-scoped settings and edit/save them a bit more manually. You can follow the CodeBank link in my signature and check out my thread on Protected Configuration for an example of how to do that.
-
Dec 25th, 2018, 11:20 PM
#6
Banned
Re: [RESOLVED] Carrying My.Settings (Config File)
I am having the same issue, but for a different reason. I need to use the info saved in several my.settings listof(string) in a different application. I only resorted to using My.Settings because I can't wrap my head around setting up a database or .xml file or ini.file. I'll be reading the suggested thread, but I'd rather use a database.
-
Dec 26th, 2018, 12:27 AM
#7
Re: [RESOLVED] Carrying My.Settings (Config File)
 Originally Posted by Amerigoware
I'd rather use a database.
Then you should use one. It's not difficult and there are lots of resources around to help learn, e.g. Home & Learn. It's rare that a developer can get too far these days without knowing how to work with databases, unless you stick to very small-scale projects. If the amount of data is very small then you might just use a DataTable persisted to an XML file. You can simply add columns to a DataTable and call WriteXml on it to produce an XML file with the appropriate schema. Once you have that file, you can call ReadXml to load schema and data into a new DataTable and WriteXml to save any changes.
Last edited by jmcilhinney; Dec 26th, 2018 at 12:40 AM.
-
Dec 26th, 2018, 07:57 AM
#8
Re: [RESOLVED] Carrying My.Settings (Config File)
You can use a configuration file, just not My.Setings.... you can use the ConfigurationManager to loadf/save to alternate configuration files outside the Application.Config and User.Config and to a location of your choice. It's been a LONG time since I've done it and I don't have anything handy to offer up as an example, but I'm sure if you search for ConfigurationManager you should be able to find something on it. If I remember right, it does take some additional effort to get it set up correctly, since you have to create some custom classes to hold the settings values, but in the end if it accomplishes the goal, it's worth it. I las used it 6 or 7 years ago to store alternate database connection information for a pet project I was working on that I didn't want in the main config files.
-tg
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|