473,327 Members | 1,892 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,327 software developers and data experts.

appsetting in class doesn't work

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
Nov 16 '06 #1
16 1739
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.OpenExeC onfiguration(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" <bd*****@sgiims.comwrote in message
news:eG**************@TK2MSFTNGP04.phx.gbl...
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


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**********@NoSpam.comwrote in message
news:es**************@TK2MSFTNGP06.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="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.OpenExeC onfiguration(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" <bd*****@sgiims.comwrote in message
news:eG**************@TK2MSFTNGP04.phx.gbl...
>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



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

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.

<applicationSettings>

<TestClassApConfig.My.MySettings>

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

<value>Testvalue</value>

</setting>

</TestClassApConfig.My.MySettings>

</applicationSettings>

And indeed when I tested it using the old style app.config file
<appSettings>
<add key="TestSetting" value="TestValue"/>
</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**********@NoSpam.comwrote in message
news:es**************@TK2MSFTNGP06.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="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.OpenExeC onfiguration(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" <bd*****@sgiims.comwrote in message
news:eG**************@TK2MSFTNGP04.phx.gbl...
>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



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.

<configuration>

<appSettings>

<add key="TestSetting" value="TestValue"/>

</appSettings>

</configuration>

Check it out

S

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

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.

<applicationSettings>

<TestClassApConfig.My.MySettings>

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

<value>Testvalue</value>

</setting>

</TestClassApConfig.My.MySettings>

</applicationSettings>

And indeed when I tested it using the old style app.config file
<appSettings>
<add key="TestSetting" value="TestValue"/>
</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**********@NoSpam.comwrote in message
news:es**************@TK2MSFTNGP06.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="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.OpenExe Configuration(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" <bd*****@sgiims.comwrote in message
news:eG**************@TK2MSFTNGP04.phx.gbl...
>>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




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**********@NoSpam.comwrote in message
news:Op**************@TK2MSFTNGP02.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.

<configuration>

<appSettings>

<add key="TestSetting" value="TestValue"/>

</appSettings>

</configuration>

Check it out

S

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

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.

<applicationSettings>

<TestClassApConfig.My.MySettings>

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

<value>Testvalue</value>

</setting>

</TestClassApConfig.My.MySettings>

</applicationSettings>

And indeed when I tested it using the old style app.config file
<appSettings>
<add key="TestSetting" value="TestValue"/>
</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**********@NoSpam.comwrote in message
news:es**************@TK2MSFTNGP06.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="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.OpenEx eConfiguration(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" <bd*****@sgiims.comwrote in message
news:eG**************@TK2MSFTNGP04.phx.gbl...
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




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 "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.TestSetting
and it returned the TestValue value.

That was it.
Steve

"Robert Dufour" <bd*****@sgiims.comwrote in message
news:uN**************@TK2MSFTNGP03.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**********@NoSpam.comwrote in message
news:Op**************@TK2MSFTNGP02.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.

<configuration>

<appSettings>

<add key="TestSetting" value="TestValue"/>

</appSettings>

</configuration>

Check it out

S

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

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.

<applicationSettings>

<TestClassApConfig.My.MySettings>

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

<value>Testvalue</value>

</setting>

</TestClassApConfig.My.MySettings>

</applicationSettings>

And indeed when I tested it using the old style app.config file
<appSettings>
<add key="TestSetting" value="TestValue"/>
</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**********@NoSpam.comwrote in message
news:es**************@TK2MSFTNGP06.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="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.OpenE xeConfiguration(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" <bd*****@sgiims.comwrote in message
news:eG**************@TK2MSFTNGP04.phx.gbl...
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
>
>




Nov 16 '06 #7
That's true. The settings are project-specific.
Robin S.
----------------------------------
"Steve Long" <St**********@NoSpam.comwrote in message
news:%2****************@TK2MSFTNGP02.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.TestSetting
and it returned the TestValue value.

That was it.
Steve

"Robert Dufour" <bd*****@sgiims.comwrote in message
news:uN**************@TK2MSFTNGP03.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**********@NoSpam.comwrote in message
news:Op**************@TK2MSFTNGP02.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.

<configuration>

<appSettings>

<add key="TestSetting" value="TestValue"/>

</appSettings>

</configuration>

Check it out

S

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

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.

<applicationSettings>

<TestClassApConfig.My.MySettings>

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

<value>Testvalue</value>

</setting>

</TestClassApConfig.My.MySettings>

</applicationSettings>

And indeed when I tested it using the old style app.config file
<appSettings>
<add key="TestSetting" value="TestValue"/>
</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**********@NoSpam.comwrote in message
news:es**************@TK2MSFTNGP06.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="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.Open ExeConfiguration(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" <bd*****@sgiims.comwrote in message
news:eG**************@TK2MSFTNGP04.phx.gbl.. .
>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
>>
>>
>
>




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
applicationsettings 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 <appsetingswith the tags <addkeyit
is now using a wholly different set of XML tags.

<applicationSettings>
<TestClassApConfig.My.MySettings>
<setting name="TestSetting" serializeAs="String">
<value>Testvalue</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**********@NoSpam.comwrote in message
news:%2****************@TK2MSFTNGP02.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.TestSetting
and it returned the TestValue value.

That was it.
Steve

"Robert Dufour" <bd*****@sgiims.comwrote in message
news:uN**************@TK2MSFTNGP03.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**********@NoSpam.comwrote in message
news:Op**************@TK2MSFTNGP02.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.

<configuration>

<appSettings>

<add key="TestSetting" value="TestValue"/>

</appSettings>

</configuration>

Check it out

S

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

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.

<applicationSettings>

<TestClassApConfig.My.MySettings>

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

<value>Testvalue</value>

</setting>

</TestClassApConfig.My.MySettings>

</applicationSettings>

And indeed when I tested it using the old style app.config file
<appSettings>
<add key="TestSetting" value="TestValue"/>
</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**********@NoSpam.comwrote in message
news:es**************@TK2MSFTNGP06.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="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.Open ExeConfiguration(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" <bd*****@sgiims.comwrote in message
news:eG**************@TK2MSFTNGP04.phx.gbl.. .
>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
>>
>>
>
>




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**********@NoSpam.comwrote in message
news:%2****************@TK2MSFTNGP02.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.TestSetting
and it returned the TestValue value.

That was it.
Steve

"Robert Dufour" <bd*****@sgiims.comwrote in message
news:uN**************@TK2MSFTNGP03.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**********@NoSpam.comwrote in message
news:Op**************@TK2MSFTNGP02.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.

<configuration>

<appSettings>

<add key="TestSetting" value="TestValue"/>

</appSettings>

</configuration>

Check it out

S

"Robert Dufour" <bd*****@sgiims.comwrote in message
news:OD**************@TK2MSFTNGP04.phx.gbl...
Hi steve,
When running it I'm getting an unhandled exception error on line
s = el.Value.ToString() Object reference not set to an instance of an
object. Thats because with the line
el = cnfg.AppSettings.Settings.Item("TestSetting")
>
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.
>
<applicationSettings>
>
<TestClassApConfig.My.MySettings>
>
<setting name="TestSetting" serializeAs="String">
>
<value>Testvalue</value>
>
</setting>
>
</TestClassApConfig.My.MySettings>
>
</applicationSettings>
>
And indeed when I tested it using the old style app.config file
<appSettings>
<add key="TestSetting" value="TestValue"/>
</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**********@NoSpam.comwrote in message
news:es**************@TK2MSFTNGP06.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="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.Ope nExeConfiguration(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" <bd*****@sgiims.comwrote in message
>news:eG**************@TK2MSFTNGP04.phx.gbl. ..
>>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
>>>
>>>
>>
>>
>
>




Nov 17 '06 #10
Ok guys thanks to you both I found a way for now, far from elegant but it
works at least in my test app.
This is the typical full app.config file in Vs2005. See the bottom I added
an appsettings section.
<?xml version="1.0" encoding="utf-8" ?>

<configuration>

<configSections>

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

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

</sectionGroup>

</configSections>

<system.diagnostics>

<sources>

<!-- This section defines the logging configuration for
My.Application.Log -->

<source name="DefaultSource" switchName="DefaultSwitch">

<listeners>

<add name="FileLog"/>

<!-- Uncomment the below section to write to the Application Event Log -->

<!--<add name="EventLog"/>-->

</listeners>

</source>

</sources>

<switches>

<add name="DefaultSwitch" value="Information" />

</switches>

<sharedListeners>

<add name="FileLog"

type="Microsoft.VisualBasic.Logging.FileLogTraceLi stener,
Microsoft.VisualBasic, Version=8.0.0.0, Culture=neutral,
PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL"

initializeData="FileLogWriter"/>

<!-- Uncomment the below section and replace APPLICATION_NAME with the name
of your application to write to the Application Event Log -->

<!--<add name="EventLog" type="System.Diagnostics.EventLogTraceListener"
initializeData="APPLICATION_NAME"/-->

</sharedListeners>

</system.diagnostics>

<applicationSettings>

<TestClassApConfig.My.MySettings>

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

<value>Testvalue1</value>

</setting>

</TestClassApConfig.My.MySettings>

</applicationSettings>

<appSettings>

<add key="TestSetting" value="TestValue"/>

</appSettings>

</configuration>

In the class project, I use the code that Steve gave me. Class code snippet
is below

Imports System.Configuration.ConfigurationManager

Imports System.Configuration

Public Class Class1

Public _strTestSetting As String

Public Sub SetTestsetting()

Dim s As String

Dim cnfg As System.Configuration.Configuration

Dim el As KeyValueConfigurationElement

cnfg =
System.Configuration.ConfigurationManager.OpenExeC onfiguration(ConfigurationUserLevel.None)

el = cnfg.AppSettings.Settings.Item("TestSetting")

s = el.Value.ToString()

_strTestSetting = s

End Sub

End Class

This code used in the second class project picks up the values in the
app.config file of the startup project in the section appsettings. In the
startup project I can use My.settings("TestSetting") to pick up the value in
the applicationSettings section. Its a bit of a kludge and it means I will
have to make sure the values in the two sections are synchronized, but its
workable until I find a way to get rid of the appSettings section in the
app.config file and use only the section.

<TestClassApConfig.My.MySettings>

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

<value>Testvalue1</value>

</setting>

</TestClassApConfig.My.MySettings>

Which is the new XML format in Vs2005

Bob
"Steve Long" <St**********@NoSpam.comwrote in message
news:%2****************@TK2MSFTNGP02.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.TestSetting
and it returned the TestValue value.

That was it.
Steve

"Robert Dufour" <bd*****@sgiims.comwrote in message
news:uN**************@TK2MSFTNGP03.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**********@NoSpam.comwrote in message
news:Op**************@TK2MSFTNGP02.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.

<configuration>

<appSettings>

<add key="TestSetting" value="TestValue"/>

</appSettings>

</configuration>

Check it out

S

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

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.

<applicationSettings>

<TestClassApConfig.My.MySettings>

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

<value>Testvalue</value>

</setting>

</TestClassApConfig.My.MySettings>

</applicationSettings>

And indeed when I tested it using the old style app.config file
<appSettings>
<add key="TestSetting" value="TestValue"/>
</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**********@NoSpam.comwrote in message
news:es**************@TK2MSFTNGP06.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="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.Open ExeConfiguration(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" <bd*****@sgiims.comwrote in message
news:eG**************@TK2MSFTNGP04.phx.gbl.. .
>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
>>
>>
>
>




Nov 17 '06 #11
Ugh.That's a lot of work. I'd probably try to figure out
a way to put a public property in the project containing
the settings I wanted, and have that expose the values
to the other classes.

Congrats on finding a solution!

Robin S.
----------------------------

"Robert Dufour" <bd*****@sgiims.comwrote in message
news:Oq**************@TK2MSFTNGP04.phx.gbl...
Ok guys thanks to you both I found a way for now, far from elegant but it
works at least in my test app.
This is the typical full app.config file in Vs2005. See the bottom I added
an appsettings section.
<?xml version="1.0" encoding="utf-8" ?>

<configuration>

<configSections>

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

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

</sectionGroup>

</configSections>

<system.diagnostics>

<sources>

<!-- This section defines the logging configuration for
My.Application.Log -->

<source name="DefaultSource" switchName="DefaultSwitch">

<listeners>

<add name="FileLog"/>

<!-- Uncomment the below section to write to the Application Event Log -->

<!--<add name="EventLog"/>-->

</listeners>

</source>

</sources>

<switches>

<add name="DefaultSwitch" value="Information" />

</switches>

<sharedListeners>

<add name="FileLog"

type="Microsoft.VisualBasic.Logging.FileLogTraceLi stener,
Microsoft.VisualBasic, Version=8.0.0.0, Culture=neutral,
PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL"

initializeData="FileLogWriter"/>

<!-- Uncomment the below section and replace APPLICATION_NAME with the
name of your application to write to the Application Event Log -->

<!--<add name="EventLog" type="System.Diagnostics.EventLogTraceListener"
initializeData="APPLICATION_NAME"/-->

</sharedListeners>

</system.diagnostics>

<applicationSettings>

<TestClassApConfig.My.MySettings>

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

<value>Testvalue1</value>

</setting>

</TestClassApConfig.My.MySettings>

</applicationSettings>

<appSettings>

<add key="TestSetting" value="TestValue"/>

</appSettings>

</configuration>

In the class project, I use the code that Steve gave me. Class code
snippet is below

Imports System.Configuration.ConfigurationManager

Imports System.Configuration

Public Class Class1

Public _strTestSetting As String

Public Sub SetTestsetting()

Dim s As String

Dim cnfg As System.Configuration.Configuration

Dim el As KeyValueConfigurationElement

cnfg =
System.Configuration.ConfigurationManager.OpenExeC onfiguration(ConfigurationUserLevel.None)

el = cnfg.AppSettings.Settings.Item("TestSetting")

s = el.Value.ToString()

_strTestSetting = s

End Sub

End Class

This code used in the second class project picks up the values in the
app.config file of the startup project in the section appsettings. In the
startup project I can use My.settings("TestSetting") to pick up the value
in the applicationSettings section. Its a bit of a kludge and it means I
will have to make sure the values in the two sections are synchronized,
but its workable until I find a way to get rid of the appSettings section
in the app.config file and use only the section.

<TestClassApConfig.My.MySettings>

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

<value>Testvalue1</value>

</setting>

</TestClassApConfig.My.MySettings>

Which is the new XML format in Vs2005

Bob
"Steve Long" <St**********@NoSpam.comwrote in message
news:%2****************@TK2MSFTNGP02.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.TestSetting
and it returned the TestValue value.

That was it.
Steve

"Robert Dufour" <bd*****@sgiims.comwrote in message
news:uN**************@TK2MSFTNGP03.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**********@NoSpam.comwrote in message
news:Op**************@TK2MSFTNGP02.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.

<configuration>

<appSettings>

<add key="TestSetting" value="TestValue"/>

</appSettings>

</configuration>

Check it out

S

"Robert Dufour" <bd*****@sgiims.comwrote in message
news:OD**************@TK2MSFTNGP04.phx.gbl...
Hi steve,
When running it I'm getting an unhandled exception error on line
s = el.Value.ToString() Object reference not set to an instance of an
object. Thats because with the line
el = cnfg.AppSettings.Settings.Item("TestSetting")
>
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.
>
<applicationSettings>
>
<TestClassApConfig.My.MySettings>
>
<setting name="TestSetting" serializeAs="String">
>
<value>Testvalue</value>
>
</setting>
>
</TestClassApConfig.My.MySettings>
>
</applicationSettings>
>
And indeed when I tested it using the old style app.config file
<appSettings>
<add key="TestSetting" value="TestValue"/>
</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**********@NoSpam.comwrote in message
news:es**************@TK2MSFTNGP06.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="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.Ope nExeConfiguration(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" <bd*****@sgiims.comwrote in message
>news:eG**************@TK2MSFTNGP04.phx.gbl. ..
>>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
>>>
>>>
>>
>>
>
>




Nov 17 '06 #12
You can also pass around a SettingsContext object but I cannot figure out
how to use that darn thing.
In this object, there is the "ProjectName.My.Settings" key but I'm having a
hard time getting at it.

Uhg. Shouldn't this be easier than this?
Theoretically, you should be able to get down to the setting that you want
through this SettingsContext object. Anybody???

S

"RobinS" <Ro****@NoSpam.yah.nonewrote in message
news:BN******************************@comcast.com. ..
Ugh.That's a lot of work. I'd probably try to figure out
a way to put a public property in the project containing
the settings I wanted, and have that expose the values
to the other classes.

Congrats on finding a solution!

Robin S.
----------------------------

"Robert Dufour" <bd*****@sgiims.comwrote in message
news:Oq**************@TK2MSFTNGP04.phx.gbl...
>Ok guys thanks to you both I found a way for now, far from elegant but it
works at least in my test app.
This is the typical full app.config file in Vs2005. See the bottom I
added an appsettings section.
<?xml version="1.0" encoding="utf-8" ?>

<configuration>

<configSections>

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

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

</sectionGroup>

</configSections>

<system.diagnostics>

<sources>

<!-- This section defines the logging configuration for
My.Application.Log -->

<source name="DefaultSource" switchName="DefaultSwitch">

<listeners>

<add name="FileLog"/>

<!-- Uncomment the below section to write to the Application Event
Log -->

<!--<add name="EventLog"/>-->

</listeners>

</source>

</sources>

<switches>

<add name="DefaultSwitch" value="Information" />

</switches>

<sharedListeners>

<add name="FileLog"

type="Microsoft.VisualBasic.Logging.FileLogTraceL istener,
Microsoft.VisualBasic, Version=8.0.0.0, Culture=neutral,
PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL"

initializeData="FileLogWriter"/>

<!-- Uncomment the below section and replace APPLICATION_NAME with the
name of your application to write to the Application Event Log -->

<!--<add name="EventLog" type="System.Diagnostics.EventLogTraceListener"
initializeData="APPLICATION_NAME"/-->

</sharedListeners>

</system.diagnostics>

<applicationSettings>

<TestClassApConfig.My.MySettings>

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

<value>Testvalue1</value>

</setting>

</TestClassApConfig.My.MySettings>

</applicationSettings>

<appSettings>

<add key="TestSetting" value="TestValue"/>

</appSettings>

</configuration>

In the class project, I use the code that Steve gave me. Class code
snippet is below

Imports System.Configuration.ConfigurationManager

Imports System.Configuration

Public Class Class1

Public _strTestSetting As String

Public Sub SetTestsetting()

Dim s As String

Dim cnfg As System.Configuration.Configuration

Dim el As KeyValueConfigurationElement

cnfg =
System.Configuration.ConfigurationManager.OpenExe Configuration(ConfigurationUserLevel.None)

el = cnfg.AppSettings.Settings.Item("TestSetting")

s = el.Value.ToString()

_strTestSetting = s

End Sub

End Class

This code used in the second class project picks up the values in the
app.config file of the startup project in the section appsettings. In the
startup project I can use My.settings("TestSetting") to pick up the value
in the applicationSettings section. Its a bit of a kludge and it means I
will have to make sure the values in the two sections are synchronized,
but its workable until I find a way to get rid of the appSettings section
in the app.config file and use only the section.

<TestClassApConfig.My.MySettings>

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

<value>Testvalue1</value>

</setting>

</TestClassApConfig.My.MySettings>

Which is the new XML format in Vs2005

Bob
"Steve Long" <St**********@NoSpam.comwrote in message
news:%2****************@TK2MSFTNGP02.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.TestSetting
and it returned the TestValue value.

That was it.
Steve

"Robert Dufour" <bd*****@sgiims.comwrote in message
news:uN**************@TK2MSFTNGP03.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**********@NoSpam.comwrote in message
news:Op**************@TK2MSFTNGP02.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.
>
<configuration>
>
<appSettings>
>
<add key="TestSetting" value="TestValue"/>
>
</appSettings>
>
</configuration>
>
Check it out
>
S
>
"Robert Dufour" <bd*****@sgiims.comwrote in message
news:OD**************@TK2MSFTNGP04.phx.gbl.. .
>Hi steve,
>When running it I'm getting an unhandled exception error on line
>s = el.Value.ToString() Object reference not set to an instance of an
>object. Thats because with the line
>el = cnfg.AppSettings.Settings.Item("TestSetting")
>>
>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.
>>
><applicationSettings>
>>
><TestClassApConfig.My.MySettings>
>>
><setting name="TestSetting" serializeAs="String">
>>
><value>Testvalue</value>
>>
></setting>
>>
></TestClassApConfig.My.MySettings>
>>
></applicationSettings>
>>
>And indeed when I tested it using the old style app.config file
><appSettings>
><add key="TestSetting" value="TestValue"/>
></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**********@NoSpam.comwrote in message
>news:es**************@TK2MSFTNGP06.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="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.Op enExeConfiguration(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" <bd*****@sgiims.comwrote in message
>>news:eG**************@TK2MSFTNGP04.phx.gbl.. .
>>>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
>>>>
>>>>
>>>
>>>
>>
>>
>
>




Nov 17 '06 #13
Robert, if you read this article:
http://visualbasic.about.com/od/usin...ppsettings.htm
I think it may make you want to hurl at what MS has done with configuration
files in general.
I created an assembly for use in my applications to handle application
settings. It uses the tag format of VS2003 and allows for multiple sections.
The main difference in this assembly is that you pass in the name of the
section along with the name of the key to get the value for said key.
Additionally, at a later time, I realized that I needed the capability to
create these config files on the fly, since that time, there was a second
class placed in the assembly CAppInit2 that will do just that.
Other than that, it works pretty much like the old config files worked. But,
you pass in the pathFileName to load a configuration file (a bit of freedom
right there), and, you can change a config file, while the app is running
(outside of the app), and this assembly will pickup those changes and reload
itself. Let me know if you want the code, I'd be happy to share as this
stuff that MS has done just looks horrific to me.

S

"Robert Dufour" <bd*****@sgiims.comwrote in message
news:Oq**************@TK2MSFTNGP04.phx.gbl...
Ok guys thanks to you both I found a way for now, far from elegant but it
works at least in my test app.
This is the typical full app.config file in Vs2005. See the bottom I added
an appsettings section.
<?xml version="1.0" encoding="utf-8" ?>

<configuration>

<configSections>

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

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

</sectionGroup>

</configSections>

<system.diagnostics>

<sources>

<!-- This section defines the logging configuration for
My.Application.Log -->

<source name="DefaultSource" switchName="DefaultSwitch">

<listeners>

<add name="FileLog"/>

<!-- Uncomment the below section to write to the Application Event Log -->

<!--<add name="EventLog"/>-->

</listeners>

</source>

</sources>

<switches>

<add name="DefaultSwitch" value="Information" />

</switches>

<sharedListeners>

<add name="FileLog"

type="Microsoft.VisualBasic.Logging.FileLogTraceLi stener,
Microsoft.VisualBasic, Version=8.0.0.0, Culture=neutral,
PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL"

initializeData="FileLogWriter"/>

<!-- Uncomment the below section and replace APPLICATION_NAME with the
name of your application to write to the Application Event Log -->

<!--<add name="EventLog" type="System.Diagnostics.EventLogTraceListener"
initializeData="APPLICATION_NAME"/-->

</sharedListeners>

</system.diagnostics>

<applicationSettings>

<TestClassApConfig.My.MySettings>

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

<value>Testvalue1</value>

</setting>

</TestClassApConfig.My.MySettings>

</applicationSettings>

<appSettings>

<add key="TestSetting" value="TestValue"/>

</appSettings>

</configuration>

In the class project, I use the code that Steve gave me. Class code
snippet is below

Imports System.Configuration.ConfigurationManager

Imports System.Configuration

Public Class Class1

Public _strTestSetting As String

Public Sub SetTestsetting()

Dim s As String

Dim cnfg As System.Configuration.Configuration

Dim el As KeyValueConfigurationElement

cnfg =
System.Configuration.ConfigurationManager.OpenExeC onfiguration(ConfigurationUserLevel.None)

el = cnfg.AppSettings.Settings.Item("TestSetting")

s = el.Value.ToString()

_strTestSetting = s

End Sub

End Class

This code used in the second class project picks up the values in the
app.config file of the startup project in the section appsettings. In the
startup project I can use My.settings("TestSetting") to pick up the value
in the applicationSettings section. Its a bit of a kludge and it means I
will have to make sure the values in the two sections are synchronized,
but its workable until I find a way to get rid of the appSettings section
in the app.config file and use only the section.

<TestClassApConfig.My.MySettings>

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

<value>Testvalue1</value>

</setting>

</TestClassApConfig.My.MySettings>

Which is the new XML format in Vs2005

Bob
"Steve Long" <St**********@NoSpam.comwrote in message
news:%2****************@TK2MSFTNGP02.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.TestSetting
and it returned the TestValue value.

That was it.
Steve

"Robert Dufour" <bd*****@sgiims.comwrote in message
news:uN**************@TK2MSFTNGP03.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**********@NoSpam.comwrote in message
news:Op**************@TK2MSFTNGP02.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.

<configuration>

<appSettings>

<add key="TestSetting" value="TestValue"/>

</appSettings>

</configuration>

Check it out

S

"Robert Dufour" <bd*****@sgiims.comwrote in message
news:OD**************@TK2MSFTNGP04.phx.gbl...
Hi steve,
When running it I'm getting an unhandled exception error on line
s = el.Value.ToString() Object reference not set to an instance of an
object. Thats because with the line
el = cnfg.AppSettings.Settings.Item("TestSetting")
>
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.
>
<applicationSettings>
>
<TestClassApConfig.My.MySettings>
>
<setting name="TestSetting" serializeAs="String">
>
<value>Testvalue</value>
>
</setting>
>
</TestClassApConfig.My.MySettings>
>
</applicationSettings>
>
And indeed when I tested it using the old style app.config file
<appSettings>
<add key="TestSetting" value="TestValue"/>
</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**********@NoSpam.comwrote in message
news:es**************@TK2MSFTNGP06.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="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.Ope nExeConfiguration(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" <bd*****@sgiims.comwrote in message
>news:eG**************@TK2MSFTNGP04.phx.gbl. ..
>>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
>>>
>>>
>>
>>
>
>




Nov 17 '06 #14
That's a heck of an idea, now why didn't I think of that:-).
That way I can use the my.settings feature to set the properties on startup
of the app and not have to maintain two sections in the app.config file.
I'm going to test that tomorrow.

Thanks,
Bob
"RobinS" <Ro****@NoSpam.yah.nonewrote in message
news:BN******************************@comcast.com. ..
Ugh.That's a lot of work. I'd probably try to figure out
a way to put a public property in the project containing
the settings I wanted, and have that expose the values
to the other classes.

Congrats on finding a solution!

Robin S.
----------------------------

"Robert Dufour" <bd*****@sgiims.comwrote in message
news:Oq**************@TK2MSFTNGP04.phx.gbl...
>Ok guys thanks to you both I found a way for now, far from elegant but it
works at least in my test app.
This is the typical full app.config file in Vs2005. See the bottom I
added an appsettings section.
<?xml version="1.0" encoding="utf-8" ?>

<configuration>

<configSections>

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

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

</sectionGroup>

</configSections>

<system.diagnostics>

<sources>

<!-- This section defines the logging configuration for
My.Application.Log -->

<source name="DefaultSource" switchName="DefaultSwitch">

<listeners>

<add name="FileLog"/>

<!-- Uncomment the below section to write to the Application Event
Log -->

<!--<add name="EventLog"/>-->

</listeners>

</source>

</sources>

<switches>

<add name="DefaultSwitch" value="Information" />

</switches>

<sharedListeners>

<add name="FileLog"

type="Microsoft.VisualBasic.Logging.FileLogTraceL istener,
Microsoft.VisualBasic, Version=8.0.0.0, Culture=neutral,
PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL"

initializeData="FileLogWriter"/>

<!-- Uncomment the below section and replace APPLICATION_NAME with the
name of your application to write to the Application Event Log -->

<!--<add name="EventLog" type="System.Diagnostics.EventLogTraceListener"
initializeData="APPLICATION_NAME"/-->

</sharedListeners>

</system.diagnostics>

<applicationSettings>

<TestClassApConfig.My.MySettings>

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

<value>Testvalue1</value>

</setting>

</TestClassApConfig.My.MySettings>

</applicationSettings>

<appSettings>

<add key="TestSetting" value="TestValue"/>

</appSettings>

</configuration>

In the class project, I use the code that Steve gave me. Class code
snippet is below

Imports System.Configuration.ConfigurationManager

Imports System.Configuration

Public Class Class1

Public _strTestSetting As String

Public Sub SetTestsetting()

Dim s As String

Dim cnfg As System.Configuration.Configuration

Dim el As KeyValueConfigurationElement

cnfg =
System.Configuration.ConfigurationManager.OpenExe Configuration(ConfigurationUserLevel.None)

el = cnfg.AppSettings.Settings.Item("TestSetting")

s = el.Value.ToString()

_strTestSetting = s

End Sub

End Class

This code used in the second class project picks up the values in the
app.config file of the startup project in the section appsettings. In the
startup project I can use My.settings("TestSetting") to pick up the value
in the applicationSettings section. Its a bit of a kludge and it means I
will have to make sure the values in the two sections are synchronized,
but its workable until I find a way to get rid of the appSettings section
in the app.config file and use only the section.

<TestClassApConfig.My.MySettings>

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

<value>Testvalue1</value>

</setting>

</TestClassApConfig.My.MySettings>

Which is the new XML format in Vs2005

Bob
"Steve Long" <St**********@NoSpam.comwrote in message
news:%2****************@TK2MSFTNGP02.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.TestSetting
and it returned the TestValue value.

That was it.
Steve

"Robert Dufour" <bd*****@sgiims.comwrote in message
news:uN**************@TK2MSFTNGP03.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**********@NoSpam.comwrote in message
news:Op**************@TK2MSFTNGP02.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.
>
<configuration>
>
<appSettings>
>
<add key="TestSetting" value="TestValue"/>
>
</appSettings>
>
</configuration>
>
Check it out
>
S
>
"Robert Dufour" <bd*****@sgiims.comwrote in message
news:OD**************@TK2MSFTNGP04.phx.gbl.. .
>Hi steve,
>When running it I'm getting an unhandled exception error on line
>s = el.Value.ToString() Object reference not set to an instance of an
>object. Thats because with the line
>el = cnfg.AppSettings.Settings.Item("TestSetting")
>>
>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.
>>
><applicationSettings>
>>
><TestClassApConfig.My.MySettings>
>>
><setting name="TestSetting" serializeAs="String">
>>
><value>Testvalue</value>
>>
></setting>
>>
></TestClassApConfig.My.MySettings>
>>
></applicationSettings>
>>
>And indeed when I tested it using the old style app.config file
><appSettings>
><add key="TestSetting" value="TestValue"/>
></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**********@NoSpam.comwrote in message
>news:es**************@TK2MSFTNGP06.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="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.Op enExeConfiguration(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" <bd*****@sgiims.comwrote in message
>>news:eG**************@TK2MSFTNGP04.phx.gbl.. .
>>>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
>>>>
>>>>
>>>
>>>
>>
>>
>
>




Nov 18 '06 #15
I'm going to control myself in commenting on MS <GGG>.
In 2003 I could easily change the config file settings from inside the app,
so I could have an application that on start would test its connection
string for instance and if it could not connect it would bring up a
configuration string modification and testing screen, so if the admin
changed the server name, no problem, easy to fix. In 2005 standard
application scope settings can't be changed. Nice going. MS just decided
that you should not do that. Now we gotta play in the config files with
notepad, Thanks a lot and it just gets better as you go along.

Anyways, yes Steve I would appreciate a copy of the assemblies you made, I
will surely try to use them.

Bob

"Steve Long" <St**********@NoSpam.comwrote in message
news:Oz**************@TK2MSFTNGP06.phx.gbl...
Robert, if you read this article:
http://visualbasic.about.com/od/usin...ppsettings.htm
I think it may make you want to hurl at what MS has done with
configuration files in general.
I created an assembly for use in my applications to handle application
settings. It uses the tag format of VS2003 and allows for multiple
sections. The main difference in this assembly is that you pass in the
name of the section along with the name of the key to get the value for
said key.
Additionally, at a later time, I realized that I needed the capability to
create these config files on the fly, since that time, there was a second
class placed in the assembly CAppInit2 that will do just that.
Other than that, it works pretty much like the old config files worked.
But, you pass in the pathFileName to load a configuration file (a bit of
freedom right there), and, you can change a config file, while the app is
running (outside of the app), and this assembly will pickup those changes
and reload itself. Let me know if you want the code, I'd be happy to share
as this stuff that MS has done just looks horrific to me.

S

"Robert Dufour" <bd*****@sgiims.comwrote in message
news:Oq**************@TK2MSFTNGP04.phx.gbl...
>Ok guys thanks to you both I found a way for now, far from elegant but it
works at least in my test app.
This is the typical full app.config file in Vs2005. See the bottom I
added an appsettings section.
<?xml version="1.0" encoding="utf-8" ?>

<configuration>

<configSections>

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

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

</sectionGroup>

</configSections>

<system.diagnostics>

<sources>

<!-- This section defines the logging configuration for
My.Application.Log -->

<source name="DefaultSource" switchName="DefaultSwitch">

<listeners>

<add name="FileLog"/>

<!-- Uncomment the below section to write to the Application Event
Log -->

<!--<add name="EventLog"/>-->

</listeners>

</source>

</sources>

<switches>

<add name="DefaultSwitch" value="Information" />

</switches>

<sharedListeners>

<add name="FileLog"

type="Microsoft.VisualBasic.Logging.FileLogTraceL istener,
Microsoft.VisualBasic, Version=8.0.0.0, Culture=neutral,
PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL"

initializeData="FileLogWriter"/>

<!-- Uncomment the below section and replace APPLICATION_NAME with the
name of your application to write to the Application Event Log -->

<!--<add name="EventLog" type="System.Diagnostics.EventLogTraceListener"
initializeData="APPLICATION_NAME"/-->

</sharedListeners>

</system.diagnostics>

<applicationSettings>

<TestClassApConfig.My.MySettings>

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

<value>Testvalue1</value>

</setting>

</TestClassApConfig.My.MySettings>

</applicationSettings>

<appSettings>

<add key="TestSetting" value="TestValue"/>

</appSettings>

</configuration>

In the class project, I use the code that Steve gave me. Class code
snippet is below

Imports System.Configuration.ConfigurationManager

Imports System.Configuration

Public Class Class1

Public _strTestSetting As String

Public Sub SetTestsetting()

Dim s As String

Dim cnfg As System.Configuration.Configuration

Dim el As KeyValueConfigurationElement

cnfg =
System.Configuration.ConfigurationManager.OpenExe Configuration(ConfigurationUserLevel.None)

el = cnfg.AppSettings.Settings.Item("TestSetting")

s = el.Value.ToString()

_strTestSetting = s

End Sub

End Class

This code used in the second class project picks up the values in the
app.config file of the startup project in the section appsettings. In the
startup project I can use My.settings("TestSetting") to pick up the value
in the applicationSettings section. Its a bit of a kludge and it means I
will have to make sure the values in the two sections are synchronized,
but its workable until I find a way to get rid of the appSettings section
in the app.config file and use only the section.

<TestClassApConfig.My.MySettings>

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

<value>Testvalue1</value>

</setting>

</TestClassApConfig.My.MySettings>

Which is the new XML format in Vs2005

Bob
"Steve Long" <St**********@NoSpam.comwrote in message
news:%2****************@TK2MSFTNGP02.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.TestSetting
and it returned the TestValue value.

That was it.
Steve

"Robert Dufour" <bd*****@sgiims.comwrote in message
news:uN**************@TK2MSFTNGP03.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**********@NoSpam.comwrote in message
news:Op**************@TK2MSFTNGP02.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.
>
<configuration>
>
<appSettings>
>
<add key="TestSetting" value="TestValue"/>
>
</appSettings>
>
</configuration>
>
Check it out
>
S
>
"Robert Dufour" <bd*****@sgiims.comwrote in message
news:OD**************@TK2MSFTNGP04.phx.gbl.. .
>Hi steve,
>When running it I'm getting an unhandled exception error on line
>s = el.Value.ToString() Object reference not set to an instance of an
>object. Thats because with the line
>el = cnfg.AppSettings.Settings.Item("TestSetting")
>>
>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.
>>
><applicationSettings>
>>
><TestClassApConfig.My.MySettings>
>>
><setting name="TestSetting" serializeAs="String">
>>
><value>Testvalue</value>
>>
></setting>
>>
></TestClassApConfig.My.MySettings>
>>
></applicationSettings>
>>
>And indeed when I tested it using the old style app.config file
><appSettings>
><add key="TestSetting" value="TestValue"/>
></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**********@NoSpam.comwrote in message
>news:es**************@TK2MSFTNGP06.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="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.Op enExeConfiguration(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" <bd*****@sgiims.comwrote in message
>>news:eG**************@TK2MSFTNGP04.phx.gbl.. .
>>>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
>>>>
>>>>
>>>
>>>
>>
>>
>
>




Nov 18 '06 #16
Laziness breeds efficiency? ;-)
Hope it works; let me know.
Robin S.
---------------------------------

"rdufour" <bd*****@sgiims.comwrote in message
news:%2****************@TK2MSFTNGP04.phx.gbl...
That's a heck of an idea, now why didn't I think of that:-).
That way I can use the my.settings feature to set the properties on
startup of the app and not have to maintain two sections in the app.config
file.
I'm going to test that tomorrow.

Thanks,
Bob
"RobinS" <Ro****@NoSpam.yah.nonewrote in message
news:BN******************************@comcast.com. ..
>Ugh.That's a lot of work. I'd probably try to figure out
a way to put a public property in the project containing
the settings I wanted, and have that expose the values
to the other classes.

Congrats on finding a solution!

Robin S.
----------------------------

"Robert Dufour" <bd*****@sgiims.comwrote in message
news:Oq**************@TK2MSFTNGP04.phx.gbl...
>>Ok guys thanks to you both I found a way for now, far from elegant but
it works at least in my test app.
This is the typical full app.config file in Vs2005. See the bottom I
added an appsettings section.
<?xml version="1.0" encoding="utf-8" ?>

<configuration>

<configSections>

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

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

</sectionGroup>

</configSections>

<system.diagnostics>

<sources>

<!-- This section defines the logging configuration for
My.Application.Log -->

<source name="DefaultSource" switchName="DefaultSwitch">

<listeners>

<add name="FileLog"/>

<!-- Uncomment the below section to write to the Application Event
Log -->

<!--<add name="EventLog"/>-->

</listeners>

</source>

</sources>

<switches>

<add name="DefaultSwitch" value="Information" />

</switches>

<sharedListeners>

<add name="FileLog"

type="Microsoft.VisualBasic.Logging.FileLogTrace Listener,
Microsoft.VisualBasic, Version=8.0.0.0, Culture=neutral,
PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL"

initializeData="FileLogWriter"/>

<!-- Uncomment the below section and replace APPLICATION_NAME with the
name of your application to write to the Application Event Log -->

<!--<add name="EventLog" type="System.Diagnostics.EventLogTraceListener"
initializeData="APPLICATION_NAME"/-->

</sharedListeners>

</system.diagnostics>

<applicationSettings>

<TestClassApConfig.My.MySettings>

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

<value>Testvalue1</value>

</setting>

</TestClassApConfig.My.MySettings>

</applicationSettings>

<appSettings>

<add key="TestSetting" value="TestValue"/>

</appSettings>

</configuration>

In the class project, I use the code that Steve gave me. Class code
snippet is below

Imports System.Configuration.ConfigurationManager

Imports System.Configuration

Public Class Class1

Public _strTestSetting As String

Public Sub SetTestsetting()

Dim s As String

Dim cnfg As System.Configuration.Configuration

Dim el As KeyValueConfigurationElement

cnfg =
System.Configuration.ConfigurationManager.OpenEx eConfiguration(ConfigurationUserLevel.None)

el = cnfg.AppSettings.Settings.Item("TestSetting")

s = el.Value.ToString()

_strTestSetting = s

End Sub

End Class

This code used in the second class project picks up the values in the
app.config file of the startup project in the section appsettings. In
the startup project I can use My.settings("TestSetting") to pick up the
value in the applicationSettings section. Its a bit of a kludge and it
means I will have to make sure the values in the two sections are
synchronized, but its workable until I find a way to get rid of the
appSettings section in the app.config file and use only the section.

<TestClassApConfig.My.MySettings>

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

<value>Testvalue1</value>

</setting>

</TestClassApConfig.My.MySettings>

Which is the new XML format in Vs2005

Bob
"Steve Long" <St**********@NoSpam.comwrote in message
news:%2****************@TK2MSFTNGP02.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.TestSetting
and it returned the TestValue value.

That was it.
Steve

"Robert Dufour" <bd*****@sgiims.comwrote in message
news:uN**************@TK2MSFTNGP03.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**********@NoSpam.comwrote in message
news:Op**************@TK2MSFTNGP02.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.
>>
><configuration>
>>
><appSettings>
>>
><add key="TestSetting" value="TestValue"/>
>>
></appSettings>
>>
></configuration>
>>
>Check it out
>>
>S
>>
>"Robert Dufour" <bd*****@sgiims.comwrote in message
>news:OD**************@TK2MSFTNGP04.phx.gbl. ..
>>Hi steve,
>>When running it I'm getting an unhandled exception error on line
>>s = el.Value.ToString() Object reference not set to an instance of
>>an object. Thats because with the line
>>el = cnfg.AppSettings.Settings.Item("TestSetting")
>>>
>>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.
>>>
>><applicationSettings>
>>>
>><TestClassApConfig.My.MySettings>
>>>
>><setting name="TestSetting" serializeAs="String">
>>>
>><value>Testvalue</value>
>>>
>></setting>
>>>
>></TestClassApConfig.My.MySettings>
>>>
>></applicationSettings>
>>>
>>And indeed when I tested it using the old style app.config file
>><appSettings>
>><add key="TestSetting" value="TestValue"/>
>></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**********@NoSpam.comwrote in message
>>news:es**************@TK2MSFTNGP06.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="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.O penExeConfiguration(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" <bd*****@sgiims.comwrote in message
>>>news:eG**************@TK2MSFTNGP04.phx.gbl. ..
>>>>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
>>>>>
>>>>>
>>>>
>>>>
>>>
>>>
>>
>>
>
>




Nov 18 '06 #17

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

Similar topics

2
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...
7
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>...
166
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
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>...
1
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...
8
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...
1
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...
0
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="<%$...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.