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 9184879
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T19:09:34+00:00 2026-06-17T19:09:34+00:00

In machine.config file there are elements written there by 3rd party software so it

  • 0

In machine.config file there are elements written there by 3rd party software so it looks like this:

<configuration>
    <configSections>
    ...
    </configSections>

    ...

    <Custom>
        <Level1> ... 
        </Level1>

        <Level2> ... 
        </Level2>

        <Level3>
            <add key="key_text1" value="s1" />
            <add key="key_text2" value="s2" />
            <add key="key_text3" value="s3" />
        </Level3>
    </Custom>
</configuration>

I want to get e.g. a value (“s2”) of “value” attribute where key=”key_text2″ from configuration/Custom/Level3 node. So far, I tried to open machine.config as an XML and work from there:

Configuration config = ConfigurationManager.OpenMachineConfiguration();
XmlDocument doc = new XmlDocument();
doc.LoadXml(config.FilePath);

however, I get XmlException “Data at the root level is invalid.”. I also don’t know how to use Configuration class methods directly to get this done. Any ideas would be appreciated.

  • 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-06-17T19:09:35+00:00Added an answer on June 17, 2026 at 7:09 pm

    Use RuntimeEnvironment.SystemConfigurationFile to get machine.config location:

    XmlDocument doc = new XmlDocument();
    doc.Load(RuntimeEnvironment.SystemConfigurationFile);
    

    Also why not to use Linq to Xml?

    XDocument xdoc = XDocument.Load(RuntimeEnvironment.SystemConfigurationFile);
    var element = xdoc.XPathSelectElement("//Custom/Level3/add[@value='s2']");
    if (element != null)
        key = (string)element.Attribute("key");
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

If I put configuration settings (like membership provider) DB Connnection, etc. in the machine.config,
file c:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\CONFIG\machine.config doesn't have this element. Where these options are keeping?
i have an edited version of a config file specific for my machine. i
The machine I use is 64-bit I wrote assembly code like this: movl $0x12e48ead
i have an asp.net web app that has this in the web.config file in
In a .NET windows application to to modify a remote machine config file that
I'm trying to unit test a custom ConfigurationSection I've written, and I'd like to
I would like to add the machineKey to my machine.config since I am working
I have an ADO.NET Managed Data Provider that is registered in machine.config in DbProviderFactory
I have an app.Config that was created on the dev machine running Windows 7.

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.