Sunday, May 24, 2009

Application Settings in .Net Framework

The .Net Framework allows us to create and access values that persist from application session to application session. These values are called settings.For example, settings can be used to store user preferences, color scheme of application, or web server address used by the application.

Settings have four properties: Name (also used to access it at run-time), Type (represents type of setting), Value and Scope (can be either User or Application). A setting with Application scope represents a value that is used by the entire application regardless of the user, whereas a setting with User scope is more likely to be user-specific.

Application settings are read-only and values can be changed at design time, while User settings can be changed at run-time as well.

The Settings Editor in Visual Studio can be opened by double click Settings.settings under the Properties folder in Solution Explorer.

Loading settings at run-time

this.Title = Properties.Settings.Default.ApplicationName;

txtName.Text = Properties.Settings.Default.Name;

txtAddress.Text = Properties.Settings.Default.Address;

txtNationality.Text = Properties.Settings.Default.Nationality;

Saving user setings at run-time

Properties.Settings.Default.Name = txtName.Text;

Properties.Settings.Default.Nationality = txtNationality.Text;

Properties.Settings.Default.Address = txtAddress.Text;


Download Example

1 comment:

suchin said...

Hi Friend,! Congratulations for this nice looking blog. In this post everything about Web Development. I am also interested in latest news, Great idea you know about company background. Increasing your web traffic and page views Add, add your website in