We help IT Professionals succeed at work.

What is the best way using vb.net to save settings on a per application and per user/application basis?

3,820 Views
1 Endorsement
Last Modified: 2014-08-18
Hi Experts,

What is the best way using vb.net to save settings on a per application and per user/application basis?

One additional contraint is that I would to initialize some of the settings using my installer program, Setup Factory for Windows.

Thanks,

Regards,
Leigh
Comment
Watch Question

Raghu MutalikdesaiPassionate for code
CERTIFIED EXPERT
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION
CERTIFIED EXPERT
Most Valuable Expert 2011
Top Expert 2015

Commented:
"Best" is a subjective term, so you would have to define what best means to you.

.NET applications have the Settings file which you can set either user-level or application-level settings. Just go to Project->Properties->Settings Tab. On that tab you will see a grid for entering in your various settings. The third column is a scope column where you can set whether the property is for the user or for the application:

Screenshot
User-scoped settings end up in an XML file that is in the user's profile directory; application settings end up in the application config file (in the same directory as the application). Don't be fooled:  While the application config file will show your user-scoped setting, this is more of a default value that will be provided to new users of your app. The actual value that is set for the individual users is stored in each user's profile directory.

You could use the registry as Raghu suggests in his second point, but .NET leans toward XML configuration files versus using the registry. You can still access the registry in .NET, but it's not the preferred place to store configuration.

You could also use a database, but this more of a heavyweight solution. There's nothing wrong with using a database, but just be sure you plan out the database carefully so that if you ever have to make changes they won't cripple your application unnecessarily.

Author

Commented:
Thanks, Raghu and kaufmed, for your suggestions.

I will go with XML files.

Just a few questions:

1.

Can you point me to a sample project that shows how to manipulate XML settings in code?

2.

Where is the user's profile directory on Windows 7 or later?
Thanks,

Regards,
Leigh
CERTIFIED EXPERT
Most Valuable Expert 2011
Top Expert 2015
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION

Author

Commented:
Thanks, Raghu and kaufmed, for your suggestions.

kaufmed - I really appreciate your detailed advice.

Regards,
Leigh
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.