AvocadoSoftware.com

Software For Hardcore Developers
Welcome to AvocadoSoftware.com Sign in | Join | Help
in Search

Derick Baileys old blog archives - go to derickbailey.com for new contents

VS 2005 Cool Feature No. 4: Settings Editor Screen and Stronly Typed, Read/Write Settings Object

Settings Editor Screen and Stronly Typed, Read/Write Settings Object

Adding an App.Config file to your application is no longer done through the Add File option for your project. Rather, you go into the properties for your project, and click the "Settings" tab. Here, you'll be able to add and edit settings that we would have previously stored in the "appSettings" portion of the .config file.

You also have the option of specifying the variable's Scope as being Application or User. Applicaiton level settings are global for the application - all users get the same setting. User level settings are exactly that - each user gets their own value for this setting. Specifiying the "Type" allows the compiler to create a strongly typed settings object. After adding a single item, the app.config file is automatically added to your project, and contains this xml:

xml version="1.0" encoding="utf-8" ?>

<configuration>

<configSections>

<sectionGroup name="applicationSettings" type="System.Configuration.ApplicationSettingsGroup, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" >

<section name="WindowsApplication1.My.MySettings" type="System.Configuration.ClientSettingsSection, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />

sectionGroup>

configSections>

<applicationSettings>

<WindowsApplication1.My.MySettings>

<setting name="MyTestSetting" serializeAs="String">

<value>My Test Valuevalue>

setting>

WindowsApplication1.My.MySettings>

applicationSettings>

configuration>

As you can see, this is quite a bit more complex than the old "appSettings" section with the add name/value tags. Nice to see that this includes a built in editor, to keep it simple. Once you've completed your settings, you can access them in code using the "My" keyword in VB.

So much easier to get to these settings now that they are strongly typed. MSDN Library For Visual Studio has this to say about the Application Settings screen:

Settings Grid

The settings grid is used to configure the application settings.

Name

Enter the name of the application setting in this field.

Type

Use the drop-down list to select a type for the setting. The most commonly used types appear in the drop-down list—for example, String, connection string, System.Drawing.Font, and so on. You can select another type by selecting Browse at the end of the list, and choosing a type from the Select a Type Dialog Box. Notice that after you have selected a type from this dialog box, that type is added to the common types in the drop-down list (for the current solution only).

Scope

The Scope can be Application or User.

Application-scoped settings (such as connection strings) are associated with the application; users cannot change them at run time.

User-scoped settings (such as system fonts) are intended for user preferences; users can change them at run time.

Value

The data or value associated with the application setting. For example, if the setting is a font, its value could be Verdana, 9.75pt, style=Bold.

Unfortunately, Application level settings cannot be changed at run time. I think this was a mistake on the part of Microsoft. This means that any application that we develop, that has a configurable connection string, still has to be modified either through a custom class or through editing the .config file directly.

Published Saturday, October 29, 2005 12:15 PM by dredge
Filed Under: , ,
New Comments to this post are disabled

This Blog

Post Calendar

<October 2005>
SuMoTuWeThFrSa
2526272829301
2345678
9101112131415
16171819202122
23242526272829
303112345

Advertisement

News

this is my old blog archives - go to http://derickbailey.com for updates

Syndication

Advertisement

Powered by Community Server, by Telligent Systems