locked
Configuration Application Block RRS feed

  • Question

  • User1584648894 posted
    When using the configuration access block; I simply want to access the configured XML file (for reading) via Xpath attributes; and not have to create a Type class for the configuration items.  Is it possible to get the Configuration Access Block to read in these types of xml config files and then access them accordingly?  For example:

    Given the following config file (assume the the linkage is already provided between the web.config and the file provided below):

    <?xml version="1.0" encoding="utf-8"?>
    <
    WebFormSettings
    >
     
    <xmlSerializerSection type=
    "Configuration.ValueData, SampleWebApplication, Version=1.0.2097.14491, Culture=neutral, PublicKeyToken=null">
        <ValueData
    >
         
    <Value>SomeValue</Value
    >
       
    </ValueData
    >
     
    </xmlSerializerSection
    >
    </
    WebFormSettings>

    I had to create a Class (called ValueData) to read the given config as shown below:

    ValueData configData = ConfigurationManager.GetConfiguration("WebFormSettings") as ValueData;

    Instead, I would prefer to access some config items via the following:

    string configData = ConfigurationManager.GetConfiguration("WebFormSettings/ValueData/Value") as string;

    Which in this case should return "SomeValue"

    Thursday, September 29, 2005 7:46 PM

All replies

  • User-1683643362 posted
    I don't know about using the config block to handle that, but you can do something like this to reference the xpath once you have loaded the file into an XML object:

    XDoc.SelectNodes("THEPATH/TOMY/XMLVALUE")[0].InnerText;

    Where XDoc is your XML document object.

    Hope that helps.

    Thursday, October 27, 2005 7:54 PM