[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2712
  • Last Modified:

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
1
LeighWardle
Asked:
LeighWardle
  • 2
  • 2
2 Solutions
 
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
 
LeighWardleAuthor Commented:
Thanks, Raghu and kaufmed, for your suggestions.

kaufmed - I really appreciate your detailed advice.

Regards,
Leigh
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now