views:

83

answers:

2

I've read all of the examples and I've yet to figure out how to get information out of the web.config file using applicationSettings (as opposed to appSettings). I have the following for my configSections:

<configSections>
    <sectionGroup name="applicationSettings" type="System.Configuration.ApplicationSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
        <section name="ExcelREST.FDAllUpAvailabilityTable.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false"/>
    </sectionGroup>
</configSections>

Then, for applicationSettings I have:

<applicationSettings>
    <ExcelREST.FDAllUpAvailabilityTable.Settings>
        <setting name="RESTPageURI" serializeAs="String">
            <value>http://team/_vti_bin/ExcelRest.aspx&lt;/value&gt;
        </setting>
        <setting name="WorkbookLocation" serializeAs="String">
            <value>/sites/tel/Shared Documents/FD Dashboard Reports.xlsx</value>
        </setting>
        <setting name="ResourceLoction" serializeAs="String">
            <value>/model/Tables('FDAllUpAvailabilityTable')?$format=html&amp;Ranges('MonthParameter')={0}</value>
        </setting>
    </ExcelREST.FDAllUpAvailabilityTable.Settings>
</applicationSettings>

Now, I suspect that I may be making an assumption that's not valid; namely, that the appropriate classes will be generated to access my configuration information by Visual Studio (2010). I've simplified the example in that I really want to have several <section name="..." > within configSections.

What (probably obvious) step am I missing here? (I'm coding in C# and this is an ASP.NET 4.0 MVC application.) I'm about ready to bag it and just go with the simplistic appSettings.

Thanks!

+1  A: 

I think you really want to make a custom configuration section not a custom application settings element.

Wyatt Barnett
A: 

If you have done the above correctly, you can just access your data via

string restPageUri = ExcelREST.FDAllUpAvailabilityTable.Settings.Default.RESTPageURI;

string workbookLocation= ExcelREST.FDAllUpAvailabilityTable.Settings.Default.WorkbookLocation;

However, it looks like you have created these entries by typing them directly into your web.config. If you do not have a ExcelREST.FDAllUpAvailabilityTable.Settings class in your project, then you have to create one. The best way to create one is to use the Visual Studio settings wizard.

Syd