Articles → .NET → My.Settings In Vb.Net
My.Settings In Vb.Net
Software
Technical Knowledge
- How to create windows application using visual studio with vb.net as a programming language?
- What is the purpose of app.config in windows application?
- What is AppData folder and what is its purpose?
My.Settings
- ‘Name’ attribute gives a unique ID to the setting.
- ‘Type’ property provides information about the type of the setting.
- ‘Scope’ helps in determining whether it is an application level settings and user level settings
- ‘Value’ helps in determining the value of the setting.
How We Can Access It
- Create a vb.net windows based application.
- In solution explorer click on ‘My Project’ folder as shown in figure below
Click to Enlarge
- A window appears with the list of tabs. Click on ‘Settings’ tab.
- The grid displayed in ‘Settings’ tab is used to configure settings. Here you find all the four attributes of a setting – Name, Type, Scope and Value.
Click to Enlarge
Scope Of Settings
- Application – Application level settings are read-only and are shared between all users of that application. These settings provide information about the URL, Web service or database connection string. These settings cannot be changed at runtime by the users as the values are associated with the application.
- User – User level settings are specific for each user. These values can be changed by the users at runtime.
How Settings Are Stored
Click to Enlarge
<?xml version="1.0" encoding="utf-8" ?><configuration><configSections><sectionGroup name="userSettings" type="System.Configuration.UserSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" ><section name="MySettingsDemo.My.MySettings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" allowExeDefinition="MachineToLocalUser" requirePermission="false" /></sectionGroup><sectionGroup name="applicationSettings" type="System.Configuration.ApplicationSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" ><section name="MySettingsDemo.My.MySettings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" /></sectionGroup></configSections><userSettings><MySettingsDemo.My.MySettings><setting name="User_Preference" serializeAs="String"><value>P1</value></setting></MySettingsDemo.My.MySettings></userSettings><applicationSettings><MySettingsDemo.My.MySettings><setting name="Server_Name" serializeAs="String"><value>ABCD</value></setting></MySettingsDemo.My.MySettings></applicationSettings></configuration>
<?xml version="1.0" encoding="utf-8"?><configuration><userSettings><MySettingsDemo.My.MySettings><setting name="User_Preference" serializeAs="String"><value>HH:MM</value></setting></MySettingsDemo.My.MySettings></userSettings></configuration>
How To Get And Set The Value Of Settings
My.Settings.<setting_name> = value; like 'My.Settings.User_Preference = "HH:MM"
Variable_name = My.Settings.<setting_name>;