How to Use the New Application Settings in VB.NET
< Continued from page 3
After changing the background color in an example application, let's take a closer look at app.config. (You can examine it using VB.NET by double clicking it.) Here's just the settings part of that file showing a bound setting and an unbound string setting.
When a setting is bound to a control, the actual "user" settings applied in your project aren't saved here, however. They're stored in the location in C:\Users\<user id>\AppData\Local\User.Config in a location with a cryptographically generated name when the form is closed (in my experiments). Once created, I can't see where these files are ever deleted again. But since they're re-created on demand, I haven't found a reason why they can't be deleted manually.
When you examine the XML elements in this file, you will notice that some things are missing. First, the type of the setting and second, whether they're bound to a control or not. You might think that you can edit the app.config file directly since it's just an XML file to add and remove settings. That doesn't work for any file type except String. In the illustration below, the setting DirectEditSetting was added directly to the app.config file. When the Project Properties dialog is opened, VB.NET helpfully adds it, but to where?
--------
Click Here to display the illustration
Click the Back button on your browser to return
--------
The answer is that the hidden file, Settings.Designer.vb, contains the file type - embedded in the code.
The bottom line is, in nearly all cases, use the designers in VB.NET to manage settings. Don't edit the XML directly.
The app.config file is copied directly to a new file name, <yourProjectName>.exe.config, in the output directory (bin or Release) when your project is built so it can be included when the system is installed.
Synchronize Button
I was not able to get the Synchronize button to do what Microsoft's documentation said it should do: delete User.config files. I was able to find quite a few unanswered questions from people with the same problem. I think this is a bug in VB.NET. If anyone has any wisdom to share on this point, I'd love to hear it. Here's what happens in all cases when I click the Synchronize button.
--------
Click Here to display the illustration
Click the Back button on your browser to return
--------
Do you need to persist the high score for the hot new game you're coding? Maybe the previous order for an online catalog? This could be exactly what you're looking for.
After changing the background color in an example application, let's take a closer look at app.config. (You can examine it using VB.NET by double clicking it.) Here's just the settings part of that file showing a bound setting and an unbound string setting.
<userSettings> <TestUserConfig.My.MySettings> <setting name="myBackColor" serializeAs="String"> <value>Yellow</value> </setting> <setting name="Billionaire" serializeAs="String"> <value>"Bill"</value> </setting> </TestUserConfig.My.MySettings> </userSettings>
When a setting is bound to a control, the actual "user" settings applied in your project aren't saved here, however. They're stored in the location in C:\Users\<user id>\AppData\Local\User.Config in a location with a cryptographically generated name when the form is closed (in my experiments). Once created, I can't see where these files are ever deleted again. But since they're re-created on demand, I haven't found a reason why they can't be deleted manually.
When you examine the XML elements in this file, you will notice that some things are missing. First, the type of the setting and second, whether they're bound to a control or not. You might think that you can edit the app.config file directly since it's just an XML file to add and remove settings. That doesn't work for any file type except String. In the illustration below, the setting DirectEditSetting was added directly to the app.config file. When the Project Properties dialog is opened, VB.NET helpfully adds it, but to where?
--------
Click Here to display the illustration
Click the Back button on your browser to return
--------
The answer is that the hidden file, Settings.Designer.vb, contains the file type - embedded in the code.
Public Property DirectEditSetting() As String Get Return CType(Me("DirectEditSetting"),String) End Get Set Me("DirectEditSetting") = value End Set End Property
The bottom line is, in nearly all cases, use the designers in VB.NET to manage settings. Don't edit the XML directly.
The app.config file is copied directly to a new file name, <yourProjectName>.exe.config, in the output directory (bin or Release) when your project is built so it can be included when the system is installed.
Synchronize Button
I was not able to get the Synchronize button to do what Microsoft's documentation said it should do: delete User.config files. I was able to find quite a few unanswered questions from people with the same problem. I think this is a bug in VB.NET. If anyone has any wisdom to share on this point, I'd love to hear it. Here's what happens in all cases when I click the Synchronize button.
--------
Click Here to display the illustration
Click the Back button on your browser to return
--------
Do you need to persist the high score for the hot new game you're coding? Maybe the previous order for an online catalog? This could be exactly what you're looking for.