[dba-VB] VS2005: Storing application settings

Barbara Ryan BarbaraRyan at cox.net
Thu Feb 28 06:13:09 CST 2008


I'm just getting started in ASP.NET...but, will this example help?....Barb

Setting Values at Run Time

Some applications are built with administration tools that can update the
application's settings.  In ASP.NET 2.0, we can modify settings in the
web.config in our code.  This is something we would want to do in response
to a button's click event.  The sample code below shows how easy it is to
modify an application setting in ASP.NET 2.0.

Listing 8

Protected Sub btnUpdateSetting_Click(ByVal sender AsObject, ByVal e As
System.EventArgs) _
 Handles btnUpdateSetting.Click
 
Dim cfg As Configuration
cfg = WebConfigurationManager.OpenWebConfiguration("~")
 
Dim setting As KeyValueConfigurationElement = _
CType(cfg.AppSettings.Settings("MySetting"),KeyValueConfigurationElement)
 
If Not setting Is Nothing Then
  setting.Value = "New Value Setting"
  cfg.Save()
End If
End Sub

-----Original Message-----
From: dba-vb-bounces at databaseadvisors.com
[mailto:dba-vb-bounces at databaseadvisors.com] On Behalf Of Gustav Brock
Sent: Thursday, February 28, 2008 5:00 AM
To: dba-vb at databaseadvisors.com
Subject: Re: [dba-VB] VS2005: Storing application settings

Hi John

I had a look but unfortunately it seems as your demo form only deals with
the settings for the form.

What I am after is an option to - from code - not only read but also write
the application settings as shown on tab Settings when you open the
project's Properties from menu Project (bottom entry).
These can be read easily but only written to if you attack the underlying
XML file which I don't like - I mean, if the settings are read-only it is
for a reason, though dull.

So I wondered what others do to persistently save various application
settings?

/gustav

>>> Johncliviger at aol.com 27-02-2008 18:50 >>>
Gustav
 
I may have an vb.net 2005 app that contains the settings info you're  after.

It needs sending as an attachement. Got an address?
 
johnc 



_______________________________________________
dba-VB mailing list
dba-VB at databaseadvisors.com
http://databaseadvisors.com/mailman/listinfo/dba-vb
http://www.databaseadvisors.com




More information about the dba-VB mailing list