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

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
LVL 1
LeighWardleAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Raghu MutalikdesaiSenior Manager in a leading IT Services companyCommented:
I can think of 3 ways:
1. Create XML per User and per Application. Save this XML in the application directory or User Profile. Manipulate XML as per your need using classes from System.Xml namespace
2. If the settings data is minimal, you can use Registry. .NET library provides implicit functions in VB.NET to manipulate data in registry
3. If your application uses a Database, then this is the best option. You could create couple of tables to store the settings
1
käµfm³d 👽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.
0
LeighWardleAuthor 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
0
käµfm³d 👽Commented:
1 - In VB it's quite easy:

My.Settings.[name you put in name column in my screenshot above]

If you want to update setting values you just assign to the property as you would any other and then call:

My.Settings.Save()

Open in new window


2 - It's under the AppData folder. If you don't specify a company name for your application in the Assembly Information file, then it will be under a folder that has the same name as your application; otherwise, it will be under a folder named the same as what you put for your company name:

Screenshot
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
LeighWardleAuthor Commented:
Thanks, Raghu and kaufmed, for your suggestions.

kaufmed - I really appreciate your detailed advice.

Regards,
Leigh
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.