views:

40

answers:

2

I'm trying to use the following command:

Dim xmlFilePath As String = _
    System.Configuration.ConfigurationManager.AppSettings("XmlFilePath")

to retrieve the following setting:

<applicationSettings>
    <MySolution.WebProject.My.MySettings>
        <setting name="XmlFilePath" serializeAs="String">
            <value>C:\ASP.NET\Folder\MessageLog</value>
        </setting>
    </MySolution.WebProject.My.MySettings>
</applicationSettings>

However, xmlFilePath shows up as Nothing after that line of code is run.

What's the correct code to get a setting out of the web.config file in an ASP.NET application?

NOTE: Although you can add keys individually to the <appsettings> tag, I'm trying to figure out how to use it with the "Settings" tab in the project's properties.

+4  A: 

Typically i see see this as being done different way.

<appSettings>
    <add key="XmlFilePath" value="C:\yourpath here" />
</appSettings>

Then you would use the method you describe, as that is the way that the "ConfigurationManager" works.

Mitchel Sellers
Hmm...maybe I did it wrong. I added the setting via the "Settings" tab in the project's properties window and it generated the deeply nested settings.
Ben McCormack
+1  A: 

Look in

My.MySettings.Default.XmlFilePath
Albin Sunnanbo
What's with the downvote? Replace `System.Configuration.ConfigurationManager.AppSettings("XmlFilePath")`with this and you can access your setting.
Albin Sunnanbo
I don't understand why you received the downvote either. I think that may be the answer I'm looking for. I'll it when I get into work today. Thanks!
Ben McCormack
This ended up being exactly what I was looking for. Thanks!
Ben McCormack