I am trying to load up an XML document in MVC in the "HomeController"
I want this document to load up in everything under the /Home/ directory so have my class:
public HomeController()
{ }
And inside this I have the code that I want to connect to the XML with:
//Now set up the config xml read
XmlDocument xmldoc = new XmlDocument();
xmldoc.Load(HttpContext.Server.MapPath("~/Content/settings.xml"));
XmlNodeList settings = xmldoc.SelectNodes("/settings");
XmlNodeList defaults = xmldoc.GetElementsByTagName("default");
foreach (XmlNode node in defaults)
{
string def_WebPageName = node["WebPageName "].InnerText;
}
Structure of the XML:
<settings>
<defaults>
<WebPageName>blah</WebPageName>
</defaults>
I cannot seem to locate theXML file, keep getting a "Object set to null reference" error
var filePath = HttpContext.Server.MapPath("~/Content/settings.xml"); xmldoc.Load(filePath);in order to check if the file is actually found, also, which line is the 29th ?