473,569 Members | 2,761 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

appsetting in class doesn't work

Here's the class code snippet
Imports System.Configur ation.Configura tionManager

Public Class Class1

Public _strTestSetting As String

Public Sub SetTestsetting( )

_strTestSetting = AppSettings.Get ("TestSettin g") -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.Configur ation

Public Class Form1

Private Sub Button1_Click(B yVal sender As System.Object, ByVal e As
System.EventArg s) Handles Button1.Click

Dim mycls As New clsTestconfig.C lass1

mycls.SetTestse tting()

Label1.Text = mycls._strTestS etting

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 ("TestSettin g")

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
Nov 16 '06 #1
16 1762
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="TestSettin g" value="TestValu e"/>

</appSettings>

Now the code:

Dim s As String

Dim cnfg As System.Configur ation.Configura tion

Dim el As KeyValueConfigu rationElement

cnfg =
System.Configur ation.Configura tionManager.Ope nExeConfigurati on(Configuratio nUserLevel.None )

el = cnfg.AppSetting s.Settings.Item ("TestSettin g")

s = el.Value.ToStri ng()

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" <bd*****@sgiims .comwrote in message
news:eG******** ******@TK2MSFTN GP04.phx.gbl...
Here's the class code snippet
Imports System.Configur ation.Configura tionManager

Public Class Class1

Public _strTestSetting As String

Public Sub SetTestsetting( )

_strTestSetting = AppSettings.Get ("TestSettin g") -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.Configur ation

Public Class Form1

Private Sub Button1_Click(B yVal sender As System.Object, ByVal e As
System.EventArg s) Handles Button1.Click

Dim mycls As New clsTestconfig.C lass1

mycls.SetTestse tting()

Label1.Text = mycls._strTestS etting

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 ("TestSettin g")

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


Nov 16 '06 #2
Thanks Steve I'm gonna test it out and yes, why make things simple when you
can make them complicated :-(

Bob

"Steve Long" <St**********@N oSpam.comwrote in message
news:es******** ******@TK2MSFTN GP06.phx.gbl...
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="TestSettin g" value="TestValu e"/>

</appSettings>

Now the code:

Dim s As String

Dim cnfg As System.Configur ation.Configura tion

Dim el As KeyValueConfigu rationElement

cnfg =
System.Configur ation.Configura tionManager.Ope nExeConfigurati on(Configuratio nUserLevel.None )

el = cnfg.AppSetting s.Settings.Item ("TestSettin g")

s = el.Value.ToStri ng()

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" <bd*****@sgiims .comwrote in message
news:eG******** ******@TK2MSFTN GP04.phx.gbl...
>Here's the class code snippet
Imports System.Configur ation.Configura tionManager

Public Class Class1

Public _strTestSetting As String

Public Sub SetTestsetting( )

_strTestSettin g = AppSettings.Get ("TestSettin g") -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.Configur ation

Public Class Form1

Private Sub Button1_Click(B yVal sender As System.Object, ByVal e As
System.EventAr gs) Handles Button1.Click

Dim mycls As New clsTestconfig.C lass1

mycls.SetTests etting()

Label1.Text = mycls._strTestS etting

End Sub

End Class

There's a setting TestSetting in the settings file of the project Testit

Put a breakpoint on line

_strTestSettin g = AppSettings.Get ("TestSettin g")

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



Nov 16 '06 #3
Hi steve,
When running it I'm getting an unhandled exception error on line
s = el.Value.ToStri ng() Object reference not set to an instance of an
object. Thats because with the line
el = cnfg.AppSetting s.Settings.Item ("TestSettin g")

el stays at nothing and thats no doubt because my app.config file is using
the new format generated by the settings designer in VS2005 which is as
follows.

<applicationSet tings>

<TestClassApCon fig.My.MySettin gs>

<setting name="TestSetti ng" serializeAs="St ring">

<value>Testvalu e</value>

</setting>

</TestClassApConf ig.My.MySetting s>

</applicationSett ings>

And indeed when I tested it using the old style app.config file
<appSettings>
<add key="TestSettin g" value="TestValu e"/>
</appSettings>
the code works fine.
The question now becomes, how do you retrieve the TestSetting value when you
created your app config file using the built in tools of VS2005 - creating a
new app.config file with add item-new item- application configuration and
putting application scope settings in the file by using the Myproject -
settings to write settings while developping in the IDE.

Thanks for your help,

Bob


"Steve Long" <St**********@N oSpam.comwrote in message
news:es******** ******@TK2MSFTN GP06.phx.gbl...
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="TestSettin g" value="TestValu e"/>

</appSettings>

Now the code:

Dim s As String

Dim cnfg As System.Configur ation.Configura tion

Dim el As KeyValueConfigu rationElement

cnfg =
System.Configur ation.Configura tionManager.Ope nExeConfigurati on(Configuratio nUserLevel.None )

el = cnfg.AppSetting s.Settings.Item ("TestSettin g")

s = el.Value.ToStri ng()

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" <bd*****@sgiims .comwrote in message
news:eG******** ******@TK2MSFTN GP04.phx.gbl...
>Here's the class code snippet
Imports System.Configur ation.Configura tionManager

Public Class Class1

Public _strTestSetting As String

Public Sub SetTestsetting( )

_strTestSettin g = AppSettings.Get ("TestSettin g") -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.Configur ation

Public Class Form1

Private Sub Button1_Click(B yVal sender As System.Object, ByVal e As
System.EventAr gs) Handles Button1.Click

Dim mycls As New clsTestconfig.C lass1

mycls.SetTests etting()

Label1.Text = mycls._strTestS etting

End Sub

End Class

There's a setting TestSetting in the settings file of the project Testit

Put a breakpoint on line

_strTestSettin g = AppSettings.Get ("TestSettin g")

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



Nov 16 '06 #4
Well isn't that nice of MS to take the confusion to, yet, another level...
:)
You know, you might be able to get at those setting via the My.Settings
functionality.

Alternatively here's a microcosm of my app.config file, which I included by
right cliking on my project and clicking add/ New Item and selecting the
Application Configuration item.

<configuratio n>

<appSettings>

<add key="TestSettin g" value="TestValu e"/>

</appSettings>

</configuration>

Check it out

S

"Robert Dufour" <bd*****@sgiims .comwrote in message
news:OD******** ******@TK2MSFTN GP04.phx.gbl...
Hi steve,
When running it I'm getting an unhandled exception error on line
s = el.Value.ToStri ng() Object reference not set to an instance of an
object. Thats because with the line
el = cnfg.AppSetting s.Settings.Item ("TestSettin g")

el stays at nothing and thats no doubt because my app.config file is using
the new format generated by the settings designer in VS2005 which is as
follows.

<applicationSet tings>

<TestClassApCon fig.My.MySettin gs>

<setting name="TestSetti ng" serializeAs="St ring">

<value>Testvalu e</value>

</setting>

</TestClassApConf ig.My.MySetting s>

</applicationSett ings>

And indeed when I tested it using the old style app.config file
<appSettings>
<add key="TestSettin g" value="TestValu e"/>
</appSettings>
the code works fine.
The question now becomes, how do you retrieve the TestSetting value when
you created your app config file using the built in tools of VS2005 -
creating a new app.config file with add item-new item- application
configuration and putting application scope settings in the file by using
the Myproject - settings to write settings while developping in the IDE.

Thanks for your help,

Bob


"Steve Long" <St**********@N oSpam.comwrote in message
news:es******** ******@TK2MSFTN GP06.phx.gbl...
>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="TestSettin g" value="TestValu e"/>

</appSettings>

Now the code:

Dim s As String

Dim cnfg As System.Configur ation.Configura tion

Dim el As KeyValueConfigu rationElement

cnfg =
System.Configu ration.Configur ationManager.Op enExeConfigurat ion(Configurati onUserLevel.Non e)

el = cnfg.AppSetting s.Settings.Item ("TestSettin g")

s = el.Value.ToStri ng()

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" <bd*****@sgiims .comwrote in message
news:eG******* *******@TK2MSFT NGP04.phx.gbl.. .
>>Here's the class code snippet
Imports System.Configur ation.Configura tionManager

Public Class Class1

Public _strTestSetting As String

Public Sub SetTestsetting( )

_strTestSetti ng = AppSettings.Get ("TestSettin g") -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.Configur ation

Public Class Form1

Private Sub Button1_Click(B yVal sender As System.Object, ByVal e As
System.EventA rgs) Handles Button1.Click

Dim mycls As New clsTestconfig.C lass1

mycls.SetTest setting()

Label1.Text = mycls._strTestS etting

End Sub

End Class

There's a setting TestSetting in the settings file of the project Testit

Put a breakpoint on line

_strTestSetti ng = AppSettings.Get ("TestSettin g")

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




Nov 16 '06 #5
I tried via My.settings can't seem to get to it. :-(
Jeez has anyone at MS ever heard of KISS? Like in Keep It Simple Stupid.

I'm starting to think the only way to get this project off the ground and
working is to go back to Visual Studio 2003 or even Vs 6.

Hope someone can come up with a way to get to these values in the new XML
format being used by the app.config files in Vs2005.

Thanks
Bob



"Steve Long" <St**********@N oSpam.comwrote in message
news:Op******** ******@TK2MSFTN GP02.phx.gbl...
Well isn't that nice of MS to take the confusion to, yet, another level...
:)
You know, you might be able to get at those setting via the My.Settings
functionality.

Alternatively here's a microcosm of my app.config file, which I included
by right cliking on my project and clicking add/ New Item and selecting
the Application Configuration item.

<configuratio n>

<appSettings>

<add key="TestSettin g" value="TestValu e"/>

</appSettings>

</configuration>

Check it out

S

"Robert Dufour" <bd*****@sgiims .comwrote in message
news:OD******** ******@TK2MSFTN GP04.phx.gbl...
>Hi steve,
When running it I'm getting an unhandled exception error on line
s = el.Value.ToStri ng() Object reference not set to an instance of an
object. Thats because with the line
el = cnfg.AppSetting s.Settings.Item ("TestSettin g")

el stays at nothing and thats no doubt because my app.config file is
using the new format generated by the settings designer in VS2005 which
is as follows.

<applicationSe ttings>

<TestClassApCo nfig.My.MySetti ngs>

<setting name="TestSetti ng" serializeAs="St ring">

<value>Testval ue</value>

</setting>

</TestClassApConf ig.My.MySetting s>

</applicationSett ings>

And indeed when I tested it using the old style app.config file
<appSettings >
<add key="TestSettin g" value="TestValu e"/>
</appSettings>
the code works fine.
The question now becomes, how do you retrieve the TestSetting value when
you created your app config file using the built in tools of VS2005 -
creating a new app.config file with add item-new item- application
configuratio n and putting application scope settings in the file by using
the Myproject - settings to write settings while developping in the IDE.

Thanks for your help,

Bob


"Steve Long" <St**********@N oSpam.comwrote in message
news:es******* *******@TK2MSFT NGP06.phx.gbl.. .
>>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:

<appSetting s>

<add key="TestSettin g" value="TestValu e"/>

</appSettings>

Now the code:

Dim s As String

Dim cnfg As System.Configur ation.Configura tion

Dim el As KeyValueConfigu rationElement

cnfg =
System.Config uration.Configu rationManager.O penExeConfigura tion(Configurat ionUserLevel.No ne)

el = cnfg.AppSetting s.Settings.Item ("TestSettin g")

s = el.Value.ToStri ng()

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" <bd*****@sgiims .comwrote in message
news:eG****** ********@TK2MSF TNGP04.phx.gbl. ..
Here's the class code snippet
Imports System.Configur ation.Configura tionManager

Public Class Class1

Public _strTestSetting As String

Public Sub SetTestsetting( )

_strTestSett ing = AppSettings.Get ("TestSettin g") -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.Configur ation

Public Class Form1

Private Sub Button1_Click(B yVal sender As System.Object, ByVal e As
System.Event Args) Handles Button1.Click

Dim mycls As New clsTestconfig.C lass1

mycls.SetTes tsetting()

Label1.Tex t = mycls._strTestS etting

End Sub

End Class

There's a setting TestSetting in the settings file of the project
Testit

Put a breakpoint on line

_strTestSett ing = AppSettings.Get ("TestSettin g")

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




Nov 16 '06 #6
Hi Robert. Please forgive me if I'm making assumptions here but it sort of
sounds like there's a difference here between the app.config file and the
settings enter in the designer. It looks to me, (remember I have little
experience with this), that this whole thing can get easily mucked up. So, I
started a new project, click on the project in the in the solution
expolorer, clicked properties, clicked settings, enter the "TestSettin g"
setting and gave it a default value of "TestValue" , then in the Form Load
event, I just did this:
Dim s As String = My.Setting.Test Setting
and it returned the TestValue value.

That was it.
Steve

"Robert Dufour" <bd*****@sgiims .comwrote in message
news:uN******** ******@TK2MSFTN GP03.phx.gbl...
>I tried via My.settings can't seem to get to it. :-(
Jeez has anyone at MS ever heard of KISS? Like in Keep It Simple Stupid.

I'm starting to think the only way to get this project off the ground and
working is to go back to Visual Studio 2003 or even Vs 6.

Hope someone can come up with a way to get to these values in the new XML
format being used by the app.config files in Vs2005.

Thanks
Bob



"Steve Long" <St**********@N oSpam.comwrote in message
news:Op******** ******@TK2MSFTN GP02.phx.gbl...
>Well isn't that nice of MS to take the confusion to, yet, another
level... :)
You know, you might be able to get at those setting via the My.Settings
functionalit y.

Alternativel y here's a microcosm of my app.config file, which I included
by right cliking on my project and clicking add/ New Item and selecting
the Application Configuration item.

<configuration >

<appSettings >

<add key="TestSettin g" value="TestValu e"/>

</appSettings>

</configuration>

Check it out

S

"Robert Dufour" <bd*****@sgiims .comwrote in message
news:OD******* *******@TK2MSFT NGP04.phx.gbl.. .
>>Hi steve,
When running it I'm getting an unhandled exception error on line
s = el.Value.ToStri ng() Object reference not set to an instance of an
object. Thats because with the line
el = cnfg.AppSetting s.Settings.Item ("TestSettin g")

el stays at nothing and thats no doubt because my app.config file is
using the new format generated by the settings designer in VS2005 which
is as follows.

<applicationS ettings>

<TestClassApC onfig.My.MySett ings>

<setting name="TestSetti ng" serializeAs="St ring">

<value>Testva lue</value>

</setting>

</TestClassApConf ig.My.MySetting s>

</applicationSett ings>

And indeed when I tested it using the old style app.config file
<appSetting s>
<add key="TestSettin g" value="TestValu e"/>
</appSettings>
the code works fine.
The question now becomes, how do you retrieve the TestSetting value when
you created your app config file using the built in tools of VS2005 -
creating a new app.config file with add item-new item- application
configurati on and putting application scope settings in the file by
using the Myproject - settings to write settings while developping in
the IDE.

Thanks for your help,

Bob


"Steve Long" <St**********@N oSpam.comwrote in message
news:es****** ********@TK2MSF TNGP06.phx.gbl. ..
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="TestSettin g" value="TestValu e"/>

</appSettings>

Now the code:

Dim s As String

Dim cnfg As System.Configur ation.Configura tion

Dim el As KeyValueConfigu rationElement

cnfg =
System.Confi guration.Config urationManager. OpenExeConfigur ation(Configura tionUserLevel.N one)

el = cnfg.AppSetting s.Settings.Item ("TestSettin g")

s = el.Value.ToStri ng()

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" <bd*****@sgiims .comwrote in message
news:eG***** *********@TK2MS FTNGP04.phx.gbl ...
Here's the class code snippet
Imports System.Configur ation.Configura tionManager
>
Public Class Class1
>
Public _strTestSetting As String
>
>
>
Public Sub SetTestsetting( )
>
_strTestSet ting = AppSettings.Get ("TestSettin g") -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.Configur ation
>
Public Class Form1
>
Private Sub Button1_Click(B yVal sender As System.Object, ByVal e As
System.Even tArgs) Handles Button1.Click
>
Dim mycls As New clsTestconfig.C lass1
>
mycls.SetTe stsetting()
>
Label1.Te xt = mycls._strTestS etting
>
End Sub
>
End Class
>
There's a setting TestSetting in the settings file of the project
Testit
>
Put a breakpoint on line
>
_strTestSet ting = AppSettings.Get ("TestSettin g")
>
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
>
>




Nov 16 '06 #7
That's true. The settings are project-specific.
Robin S.
----------------------------------
"Steve Long" <St**********@N oSpam.comwrote in message
news:%2******** ********@TK2MSF TNGP02.phx.gbl. ..
Hi Robert. Please forgive me if I'm making assumptions here but it sort of
sounds like there's a difference here between the app.config file and the
settings enter in the designer. It looks to me, (remember I have little
experience with this), that this whole thing can get easily mucked up. So,
I started a new project, click on the project in the in the solution
expolorer, clicked properties, clicked settings, enter the "TestSettin g"
setting and gave it a default value of "TestValue" , then in the Form Load
event, I just did this:
Dim s As String = My.Setting.Test Setting
and it returned the TestValue value.

That was it.
Steve

"Robert Dufour" <bd*****@sgiims .comwrote in message
news:uN******** ******@TK2MSFTN GP03.phx.gbl...
>>I tried via My.settings can't seem to get to it. :-(
Jeez has anyone at MS ever heard of KISS? Like in Keep It Simple Stupid.

I'm starting to think the only way to get this project off the ground and
working is to go back to Visual Studio 2003 or even Vs 6.

Hope someone can come up with a way to get to these values in the new XML
format being used by the app.config files in Vs2005.

Thanks
Bob



"Steve Long" <St**********@N oSpam.comwrote in message
news:Op******* *******@TK2MSFT NGP02.phx.gbl.. .
>>Well isn't that nice of MS to take the confusion to, yet, another
level... :)
You know, you might be able to get at those setting via the My.Settings
functionality .

Alternative ly here's a microcosm of my app.config file, which I
included by right cliking on my project and clicking add/ New Item and
selecting the Application Configuration item.

<configuratio n>

<appSetting s>

<add key="TestSettin g" value="TestValu e"/>

</appSettings>

</configuration>

Check it out

S

"Robert Dufour" <bd*****@sgiims .comwrote in message
news:OD****** ********@TK2MSF TNGP04.phx.gbl. ..
Hi steve,
When running it I'm getting an unhandled exception error on line
s = el.Value.ToStri ng() Object reference not set to an instance of an
object. Thats because with the line
el = cnfg.AppSetting s.Settings.Item ("TestSettin g")

el stays at nothing and thats no doubt because my app.config file is
using the new format generated by the settings designer in VS2005 which
is as follows.

<application Settings>

<TestClassAp Config.My.MySet tings>

<setting name="TestSetti ng" serializeAs="St ring">

<value>Testv alue</value>

</setting>

</TestClassApConf ig.My.MySetting s>

</applicationSett ings>

And indeed when I tested it using the old style app.config file
<appSettings >
<add key="TestSettin g" value="TestValu e"/>
</appSettings>
the code works fine.
The question now becomes, how do you retrieve the TestSetting value
when you created your app config file using the built in tools of
VS2005 - creating a new app.config file with add item-new item-
applicatio n configuration and putting application scope settings in the
file by using the Myproject - settings to write settings while
developpin g in the IDE.

Thanks for your help,

Bob


"Steve Long" <St**********@N oSpam.comwrote in message
news:es***** *********@TK2MS FTNGP06.phx.gbl ...
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:
>
<appSetting s>
>
<add key="TestSettin g" value="TestValu e"/>
>
</appSettings>
>
Now the code:
>
Dim s As String
>
Dim cnfg As System.Configur ation.Configura tion
>
Dim el As KeyValueConfigu rationElement
>
cnfg =
System.Conf iguration.Confi gurationManager .OpenExeConfigu ration(Configur ationUserLevel. None)
>
el = cnfg.AppSetting s.Settings.Item ("TestSettin g")
>
s = el.Value.ToStri ng()
>
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" <bd*****@sgiims .comwrote in message
news:eG**** **********@TK2M SFTNGP04.phx.gb l...
>Here's the class code snippet
>Imports System.Configur ation.Configura tionManager
>>
>Public Class Class1
>>
>Public _strTestSetting As String
>>
>>
>>
>Public Sub SetTestsetting( )
>>
>_strTestSe tting = AppSettings.Get ("TestSettin g") -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
>applicatio n scope, value Testvalue
>>
>Imports System.Configur ation
>>
>Public Class Form1
>>
>Private Sub Button1_Click(B yVal sender As System.Object, ByVal e As
>System.Eve ntArgs) Handles Button1.Click
>>
>Dim mycls As New clsTestconfig.C lass1
>>
>mycls.SetT estsetting()
>>
>Label1.Tex t = mycls._strTestS etting
>>
>End Sub
>>
>End Class
>>
>There's a setting TestSetting in the settings file of the project
>Testit
>>
>Put a breakpoint on line
>>
>_strTestSe tting = AppSettings.Get ("TestSettin g")
>>
>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
>>
>>
>
>




Nov 17 '06 #8
Yes Steve, that works but if you add a class project to your solution
(clsProject2) and that class has no form, but its called from your form in
Project1 where you have a form and then you want some code in clsProject2 to
obtain values from the appconfig file of Project1, in that case code in
clsProject2 can't get values using the my.settings. I have two projects in
the solution and I am trying to obtain settings from the app.config file of
project1 by using code in clsProject2. I could do that in Vs2003 and I can
do it in Vs2005 using the code that you sent me yesterday PROVIDING the
applicationsett ings are in the xml format that was used in Vs2003. But now
the VS2005 IDE when it creates settings creates a different syntax for
settings. Its no longer in a section <appsetingswi th the tags <addkeyit
is now using a wholly different set of XML tags.

<applicationSet tings>
<TestClassApCon fig.My.MySettin gs>
<setting name="TestSetti ng" serializeAs="St ring">
<value>Testvalu e</value>
etc...
You can get these quite simply using the my.settings IF that is in the code
in the same project as the app.config file but I can't find a way to get
these values if my code is in a second project in the solution AND if the
config file uses the XML format standard of Vs2005.

Bob
"Steve Long" <St**********@N oSpam.comwrote in message
news:%2******** ********@TK2MSF TNGP02.phx.gbl. ..
Hi Robert. Please forgive me if I'm making assumptions here but it sort of
sounds like there's a difference here between the app.config file and the
settings enter in the designer. It looks to me, (remember I have little
experience with this), that this whole thing can get easily mucked up. So,
I started a new project, click on the project in the in the solution
expolorer, clicked properties, clicked settings, enter the "TestSettin g"
setting and gave it a default value of "TestValue" , then in the Form Load
event, I just did this:
Dim s As String = My.Setting.Test Setting
and it returned the TestValue value.

That was it.
Steve

"Robert Dufour" <bd*****@sgiims .comwrote in message
news:uN******** ******@TK2MSFTN GP03.phx.gbl...
>>I tried via My.settings can't seem to get to it. :-(
Jeez has anyone at MS ever heard of KISS? Like in Keep It Simple Stupid.

I'm starting to think the only way to get this project off the ground and
working is to go back to Visual Studio 2003 or even Vs 6.

Hope someone can come up with a way to get to these values in the new XML
format being used by the app.config files in Vs2005.

Thanks
Bob



"Steve Long" <St**********@N oSpam.comwrote in message
news:Op******* *******@TK2MSFT NGP02.phx.gbl.. .
>>Well isn't that nice of MS to take the confusion to, yet, another
level... :)
You know, you might be able to get at those setting via the My.Settings
functionality .

Alternative ly here's a microcosm of my app.config file, which I
included by right cliking on my project and clicking add/ New Item and
selecting the Application Configuration item.

<configuratio n>

<appSetting s>

<add key="TestSettin g" value="TestValu e"/>

</appSettings>

</configuration>

Check it out

S

"Robert Dufour" <bd*****@sgiims .comwrote in message
news:OD****** ********@TK2MSF TNGP04.phx.gbl. ..
Hi steve,
When running it I'm getting an unhandled exception error on line
s = el.Value.ToStri ng() Object reference not set to an instance of an
object. Thats because with the line
el = cnfg.AppSetting s.Settings.Item ("TestSettin g")

el stays at nothing and thats no doubt because my app.config file is
using the new format generated by the settings designer in VS2005 which
is as follows.

<application Settings>

<TestClassAp Config.My.MySet tings>

<setting name="TestSetti ng" serializeAs="St ring">

<value>Testv alue</value>

</setting>

</TestClassApConf ig.My.MySetting s>

</applicationSett ings>

And indeed when I tested it using the old style app.config file
<appSettings >
<add key="TestSettin g" value="TestValu e"/>
</appSettings>
the code works fine.
The question now becomes, how do you retrieve the TestSetting value
when you created your app config file using the built in tools of
VS2005 - creating a new app.config file with add item-new item-
applicatio n configuration and putting application scope settings in the
file by using the Myproject - settings to write settings while
developpin g in the IDE.

Thanks for your help,

Bob


"Steve Long" <St**********@N oSpam.comwrote in message
news:es***** *********@TK2MS FTNGP06.phx.gbl ...
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:
>
<appSetting s>
>
<add key="TestSettin g" value="TestValu e"/>
>
</appSettings>
>
Now the code:
>
Dim s As String
>
Dim cnfg As System.Configur ation.Configura tion
>
Dim el As KeyValueConfigu rationElement
>
cnfg =
System.Conf iguration.Confi gurationManager .OpenExeConfigu ration(Configur ationUserLevel. None)
>
el = cnfg.AppSetting s.Settings.Item ("TestSettin g")
>
s = el.Value.ToStri ng()
>
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" <bd*****@sgiims .comwrote in message
news:eG**** **********@TK2M SFTNGP04.phx.gb l...
>Here's the class code snippet
>Imports System.Configur ation.Configura tionManager
>>
>Public Class Class1
>>
>Public _strTestSetting As String
>>
>>
>>
>Public Sub SetTestsetting( )
>>
>_strTestSe tting = AppSettings.Get ("TestSettin g") -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
>applicatio n scope, value Testvalue
>>
>Imports System.Configur ation
>>
>Public Class Form1
>>
>Private Sub Button1_Click(B yVal sender As System.Object, ByVal e As
>System.Eve ntArgs) Handles Button1.Click
>>
>Dim mycls As New clsTestconfig.C lass1
>>
>mycls.SetT estsetting()
>>
>Label1.Tex t = mycls._strTestS etting
>>
>End Sub
>>
>End Class
>>
>There's a setting TestSetting in the settings file of the project
>Testit
>>
>Put a breakpoint on line
>>
>_strTestSe tting = AppSettings.Get ("TestSettin g")
>>
>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
>>
>>
>
>




Nov 17 '06 #9
Yes Robin,
However how do you obtain config setttings from within classes that are
being reused with the new application settings XML format. The my.settings
can not get settings from the main project if it is used in a second class
project in the application. There must be a way to do this though. It was
doable in Vs2003 using the 2003 XML format for the app.config file, but in
2005 the format was changed and the technique used in 2003 no longer works
with the 2005 XML app.config format.

Bob

"RobinS" <Ro****@NoSpam. yah.nonewrote in message
news:KL******** *************** *******@comcast .com...
That's true. The settings are project-specific.
Robin S.
----------------------------------
"Steve Long" <St**********@N oSpam.comwrote in message
news:%2******** ********@TK2MSF TNGP02.phx.gbl. ..
>Hi Robert. Please forgive me if I'm making assumptions here but it sort
of sounds like there's a difference here between the app.config file and
the settings enter in the designer. It looks to me, (remember I have
little experience with this), that this whole thing can get easily mucked
up. So, I started a new project, click on the project in the in the
solution expolorer, clicked properties, clicked settings, enter the
"TestSetting " setting and gave it a default value of "TestValue" , then in
the Form Load event, I just did this:
Dim s As String = My.Setting.Test Setting
and it returned the TestValue value.

That was it.
Steve

"Robert Dufour" <bd*****@sgiims .comwrote in message
news:uN******* *******@TK2MSFT NGP03.phx.gbl.. .
>>>I tried via My.settings can't seem to get to it. :-(
Jeez has anyone at MS ever heard of KISS? Like in Keep It Simple Stupid.

I'm starting to think the only way to get this project off the ground
and working is to go back to Visual Studio 2003 or even Vs 6.

Hope someone can come up with a way to get to these values in the new
XML format being used by the app.config files in Vs2005.

Thanks
Bob



"Steve Long" <St**********@N oSpam.comwrote in message
news:Op****** ********@TK2MSF TNGP02.phx.gbl. ..
Well isn't that nice of MS to take the confusion to, yet, another
level... :)
You know, you might be able to get at those setting via the My.Settings
functionalit y.

Alternativel y here's a microcosm of my app.config file, which I
included by right cliking on my project and clicking add/ New Item and
selecting the Application Configuration item.

<configurati on>

<appSettings >

<add key="TestSettin g" value="TestValu e"/>

</appSettings>

</configuration>

Check it out

S

"Robert Dufour" <bd*****@sgiims .comwrote in message
news:OD***** *********@TK2MS FTNGP04.phx.gbl ...
Hi steve,
When running it I'm getting an unhandled exception error on line
s = el.Value.ToStri ng() Object reference not set to an instance of an
object. Thats because with the line
el = cnfg.AppSetting s.Settings.Item ("TestSettin g")
>
el stays at nothing and thats no doubt because my app.config file is
using the new format generated by the settings designer in VS2005
which is as follows.
>
<applicatio nSettings>
>
<TestClassA pConfig.My.MySe ttings>
>
<setting name="TestSetti ng" serializeAs="St ring">
>
<value>Test value</value>
>
</setting>
>
</TestClassApConf ig.My.MySetting s>
>
</applicationSett ings>
>
And indeed when I tested it using the old style app.config file
<appSetting s>
<add key="TestSettin g" value="TestValu e"/>
</appSettings>
the code works fine.
The question now becomes, how do you retrieve the TestSetting value
when you created your app config file using the built in tools of
VS2005 - creating a new app.config file with add item-new item-
applicati on configuration and putting application scope settings in
the file by using the Myproject - settings to write settings while
developpi ng in the IDE.
>
Thanks for your help,
>
Bob
>
>
>
>
"Steve Long" <St**********@N oSpam.comwrote in message
news:es**** **********@TK2M SFTNGP06.phx.gb l...
>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:
>>
><appSettin gs>
>>
><add key="TestSettin g" value="TestValu e"/>
>>
></appSettings>
>>
>Now the code:
>>
>Dim s As String
>>
>Dim cnfg As System.Configur ation.Configura tion
>>
>Dim el As KeyValueConfigu rationElement
>>
>cnfg =
>System.Con figuration.Conf igurationManage r.OpenExeConfig uration(Configu rationUserLevel .None)
>>
>el = cnfg.AppSetting s.Settings.Item ("TestSettin g")
>>
>s = el.Value.ToStri ng()
>>
>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" <bd*****@sgiims .comwrote in message
>news:eG*** ***********@TK2 MSFTNGP04.phx.g bl...
>>Here's the class code snippet
>>Imports System.Configur ation.Configura tionManager
>>>
>>Public Class Class1
>>>
>>Public _strTestSetting As String
>>>
>>>
>>>
>>Public Sub SetTestsetting( )
>>>
>>_strTestS etting = AppSettings.Get ("TestSettin g") -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
>>applicati on scope, value Testvalue
>>>
>>Imports System.Configur ation
>>>
>>Public Class Form1
>>>
>>Private Sub Button1_Click(B yVal sender As System.Object, ByVal e As
>>System.Ev entArgs) Handles Button1.Click
>>>
>>Dim mycls As New clsTestconfig.C lass1
>>>
>>mycls.Set Testsetting()
>>>
>>Label1.Te xt = mycls._strTestS etting
>>>
>>End Sub
>>>
>>End Class
>>>
>>There's a setting TestSetting in the settings file of the project
>>Testit
>>>
>>Put a breakpoint on line
>>>
>>_strTestS etting = AppSettings.Get ("TestSettin g")
>>>
>>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
>>>
>>>
>>
>>
>
>




Nov 17 '06 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
2720
by: Ellis Yu | last post by:
Dear All, I use function configurationsettings.appsetting to retrieve the connection string value which stored in a file app.config. At the beginning, it's fine that it can pick up the value according to the key passed into function. But when I make some change in the value of app.config, it still pick up the old value to me, not the...
7
2467
by: Drew McCormack | last post by:
I have a C++ template class which contains a static variable whose construction registers the class with a map. Something like this: template <typename T> class M { static Registrar<M> registrar; }; The constructor of Registrar does the registering when it is initialized.
166
8538
by: Graham | last post by:
This has to do with class variables and instances variables. Given the following: <code> class _class: var = 0 #rest of the class
2
13921
by: keith | last post by:
In my app, an executable (app.exe) calls functions from an assembly dll (subapp.dll). app.exe has config file: app.exe.config <?xml version="1.0" encoding="utf-8" ?> <configuration> <appSettings> <add key="configVal" value="exe config" /> </appSettings> </configuration>
1
1316
by: Maziar Aflatoun | last post by:
Hi everyone, I'm tring to read the appSettings from my Web.config file in Visual Studio.Net (Code behind page) and it doesn't recognize ConfigurationSettings.AppSetting? Yet it works in my .aspx page. Any idea? Thank you Maz
8
3457
by: tshad | last post by:
I cannot seem to get the asp:textbox to use classes. Style works fine. I am trying to set the textbox to act like a label in some instance so it doesn't have a border, readonly and the background is grey. I have a class set as: ..table2Label{ border-style:none; background-color:#F6F6F6; }
1
10041
by: softwareakash | last post by:
Hi I have a class library which takes some values from web config / app config files when called. I am initialising these values when my object gets called. Is there any method to find out if app Settings tag is defined in the file? here is my code for initislisation
0
816
by: Gaspar | last post by:
I'm binding an app setting to a Panel visibility. I use: <add key="Panel1_Visible" value="true"/> and then .... <asp:Panel ID="Panel3" runat="server" onload="Panel1_Load" Visible="<%$ AppSettings:Panel1_Visible %>"> </asp:Panel>
0
7697
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7612
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8120
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7672
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7968
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6283
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5512
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3640
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
937
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.