Re: appsetting in class doesn't work
- From: "Robert Dufour" <bdufour@xxxxxxxxxx>
- Date: Thu, 16 Nov 2006 14:36:23 -0500
Thanks Steve I'm gonna test it out and yes, why make things simple when you
can make them complicated :-(
Bob
"Steve Long" <Steve_Noneya@xxxxxxxxxx> wrote in message
news:esZh6WbCHHA.3524@xxxxxxxxxxxxxxxxxxxxxxx
Robert, this is my first foray into the configuration system of .NET 2.0
and it seem ridiculously difficult to me but here's how I got the value of
the item that you are trying to retrieve.
First the config file:
<appSettings>
<add key="TestSetting" value="TestValue"/>
</appSettings>
Now the code:
Dim s As String
Dim cnfg As System.Configuration.Configuration
Dim el As KeyValueConfigurationElement
cnfg =
System.Configuration.ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None)
el = cnfg.AppSettings.Settings.Item("TestSetting")
s = el.Value.ToString()
This does indeed return the value that I have "TestValue" in the config
file.
HTH
S
P.S. It seems much easier in VS2003
"Robert Dufour" <bdufour@xxxxxxxxxx> wrote in message
news:eGfK2daCHHA.1012@xxxxxxxxxxxxxxxxxxxxxxx
Here's the class code snippet
Imports System.Configuration.ConfigurationManager
Public Class Class1
Public _strTestSetting As String
Public Sub SetTestsetting()
_strTestSetting = AppSettings.Get("TestSetting") -should get the value of
TestSetting in app config file
End Sub
End Class
This is the snippet in the project calling the class -Project TestIt - To
test you should have a setting named TestSetting application scope, value
Testvalue
Imports System.Configuration
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim mycls As New clsTestconfig.Class1
mycls.SetTestsetting()
Label1.Text = mycls._strTestSetting
End Sub
End Class
There's a setting TestSetting in the settings file of the project Testit
Put a breakpoint on line
_strTestSetting = AppSettings.Get("TestSetting")
Click the button, you will see as you step over the breakpoint that the
value of _strTestSetting stays at nothing. ie, its not picking up the
value of TestSetting in app.config.
How can I get this pickup of the value to work?
Thanks for any help
Bob
.
- References:
- appsetting in class doesn't work
- From: Robert Dufour
- Re: appsetting in class doesn't work
- From: Steve Long
- appsetting in class doesn't work
- Prev by Date: Re: appsetting in class doesn't work
- Next by Date: Datagrid column width
- Previous by thread: Re: appsetting in class doesn't work
- Next by thread: Re: appsetting in class doesn't work
- Index(es):
Loading