You can read file as xml doc and parse it like that :
System.Xml.Linq.XDocument doc = System.Xml.Linq.XDocument.Parse(strValue);
var solutiuonValue = (
from f in doc.Elements().FirstOrDefault().Descendants().Where(x => x.Name.Equals("headlessWarrior"))
select f).FirstOrDefault();
Thanks - I did think about something like that, though I'd much prefer XPath to get the value :)
The Parse() method won't work with a URL, I guess? Looks like there's a Load() method I can use - if it allows loading a .config file from the Config/ folder...
The settings are in a custom .config file (custom XML format too) so I don't think the ConfigurationManager would know how to access those settings, unless it has some configuration settings of its own that could teach it how to parse that file...?
How to access a setting from a custom .config (XML) file?
Hi all,
I have a SiteSettings.config file in the Config/ folder that looks something like this:
I'd like to read the value of the headlessWarrior element from a Partial View - what's the correct way to do that?
(I can read it pretty easily from an XSLT macro with the
document()
function but I have no idea how to go about grabbing it from a Razor view.)/Chriztian
Hi Chriztian,
You can read file as xml doc and parse it like that :
Thanks, Alex
Hi Alex,
Thanks - I did think about something like that, though I'd much prefer XPath to get the value :)
The
Parse()
method won't work with a URL, I guess? Looks like there's aLoad()
method I can use - if it allows loading a .config file from the Config/ folder.../Chriztian
Hi Alex,
Can't you use standard asp.net configuratioManager to retrieve appSettings?
var warrior = System.Configuration.ConfigurationManager.AppSettings["headlessWarrior"];
You will need to add a reference to System.Configuration to get to this extension.
Hi Justin,
The settings are in a custom .config file (custom XML format too) so I don't think the ConfigurationManager would know how to access those settings, unless it has some configuration settings of its own that could teach it how to parse that file...?
/Chriztian
is working on a reply...