Articles → .NET → My.Settings In Vb.Net

My.Settings In Vb.Net






Software





Technical Knowledge




  1. How to create windows application using visual studio with vb.net as a programming language?
  2. What is the purpose of app.config in windows application?
  3. What is AppData folder and what is its purpose?

My.Settings






  1. ‘Name’ attribute gives a unique ID to the setting.
  2. ‘Type’ property provides information about the type of the setting.
  3. ‘Scope’ helps in determining whether it is an application level settings and user level settings
  4. ‘Value’ helps in determining the value of the setting.

How We Can Access It


  1. Create a vb.net windows based application.
  2. In solution explorer click on ‘My Project’ folder as shown in figure below
  3. Picture showing the project structure of the sample application
    Click to Enlarge

  4. A window appears with the list of tabs. Click on ‘Settings’ tab.
  5. 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.
  6. Picture showing the settings tab in the project properties
    Click to Enlarge



Scope Of Settings




  1. 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.
  2. User – User level settings are specific for each user. These values can be changed by the users at runtime.

How Settings Are Stored




Picture showing how the 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>;



Posted By  -  Karan Gupta
 
Posted On  -  Sunday, July 6, 2014

Query/Feedback


Your Email Id  
 
Subject 
 
Query/FeedbackCharacters remaining 250