applicationSettings vs. appSettings

applicationSettings was introduced into the .Net 2.0 Framework.  This is not the same as appSettings which most developers used 1.1, but what is the difference?

Application settings give us more control and most important, intelliscence.  To create an application setting simply view your projects properties and select Settings.

applicationSettings

Here you can see that there are more parameters than the standard appSettings.  Additionally there are the fields Type, and Scope.  This Type is used for intelliscence in Visual Studio.

Within the config file, the following section is added:

    <userSettings>
        <applicationSettings_vs_appSettings.My.MySettings>
            <setting name="MySetting" serializeAs="String">
                <value>MySettingString</value>
            </setting>
        </applicationSettings_vs_appSettings.My.MySettings>
    </userSettings> 

This allows us to use intelliscence in our application now.

        Console.WriteLine(My.Settings.MySetting)

This can be very useful and it is strongly typed so it is faster.  However, applicationSettings are only in console applications, forms applications and web applications, they do not exist in websites.  For the websites you must resort to the old appSettings standard.

To set the setting to a new value simply, set the property and save the settings.

        Console.WriteLine(My.Settings.MySetting) 'MySettingString
        My.Settings.MySetting = "new setting"
        My.Settings.Save()
        Console.WriteLine(My.Settings.MySetting) 'new setting

applicationSettings2

I am not sure why this doesn't exist in the websites.  I came across this when I was getting the error: Configuration system failed to initialize from trying to use the Configuration manager versus using My.Settings.


Posted by: kjsteuer
Posted on: 3/27/2008 at 4:45 PM
Tags: ,
Actions: E-mail | Kick it! | DZone it! | del.icio.us
Post Information: Permalink | Comments (3) | Post RSSRSS comment feed