Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6576937
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T15:34:24+00:00 2026-05-25T15:34:24+00:00

I am trying to load up an XML document in MVC in the HomeController

  • 0

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

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T15:34:25+00:00Added an answer on May 25, 2026 at 3:34 pm

    If it is a Web app you get somthing like http://yoursite/Content/settings.xml. Check whether this file path exists on the web server. If it is a WinForms app use ExecutionPath or Environment variables to get the path you need.

    You should also use something like if(File.Exists(yourFilePathHere))

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to parse and load an XML document, however I'm getting this exception
I am trying to load a xml document I created using PHP and DOM
I am trying to load a very basic XML document but everytime I get
I'm trying to load a xml document into an object XPathDocument in C#. My
I'm trying to load a document with xml in c# the name of xml
I am trying to load a 3rd party xml document using JQuery/Javascript, but without
I'm trying to load an XML document which is in Project\Data as shown below:
I have a WIX XML document that contains 2,000+ file tags. I am trying
I have an XML document in this format: <?xml version=1.0 encoding=utf-8 ?> <SupportedServices> <Service>
Hi i am trying to load XML document and populate few checkboxlist. I use

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.