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

  • Home
  • SEARCH
  • 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 5984679
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T22:24:49+00:00 2026-05-22T22:24:49+00:00

I’m working on a GUI that is able to manipulate xml files through a

  • 0

I’m working on a GUI that is able to manipulate xml files through a datagridview and have it saved to a destination of the user’s choice. This program also has a .exe.config file in which I would also like to be able to freely edit inside a datagridview, since it’s a lot more convenient than having the user manually going in to the file and changing the values accordingly.

I’ve tried declaring a dataset, and I intially thought that a .exe.config file was just an xml file, but this code does not work:

        dataSet1.ReadXml(configpath);
        bindingSource1.DataSource = dataSet1.Tables[0];
        dataGridView1.DataSource = bindingSource1;

The datagridview is empty when I ran it and i confirmed that the filepath was correct and there was no exception when i debugged the code, whereas for the other xml files I open in the GUI work perfectly fine with the data displayed. Maybe readxml() only supports.. legit xml files rather than xml configuration files? I tried googling and looking for some answers, but all I got were threads related to changing the settings by manually accessing the xml file and changing the values (stuff I already know). I’m looking to be able to have the user do what they want to do with the data and then save it. The .exe.config settings may just as well be for another program, but it is essentially an xml configuration file. I figured there wasn’t much on the web for this particular problem because settings are generally static and if they are changed, it’s pretty easy to do manually.

To sum up,

I’m looking for a method to be able to open any .exe.config file, display it in a datagridview, allow the user to be able to manipulate the data values inside, and then save the file, overwriting the previous data settings.

Any help is appreciated.
Thank you in advance!

  • tf.rz (.NET 3.5 SP1, Visual Studio 2008 C#)

EDIT: I will upload a working example of an xml file I created: I kind of want the program to be able to navigate to a .exe.config file, then open it and have it displayed like this where the setting names are the columns and the values are in the cells of the datagridview. Unfortunately I am not at my home computer to be able to do this.

  • 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-22T22:24:50+00:00Added an answer on May 22, 2026 at 10:24 pm

    This is what I used to load up and manipulate a config file. You may want to change the loadAppSettings and loadConnStrings methods to suit your needs.

    using System;
    using System.Collections.Specialized;
    using System.Linq;
    using System.Text;
    using System.Xml;
    using System.IO;
    
    
    namespace GenericManagementClasses
    {
        public class ConfigFile
        {
            private string m_ConfigFilePath;
            private XmlDocument m_XmlDoc;
    
            private FileStream fIn;
            private StreamReader sr;
            private StreamWriter sw;
    
            private OrderedDictionary m_AppSettings;
            private OrderedDictionary m_ConnectionStrings;
    
            private XmlNode m_AppSettingsNode;
            private XmlNode m_ConnectionStringsNode;
    
            #region "Properties"
            public String Path
            {
                get
                {
                    return m_ConfigFilePath;
                }
            }
    
            public OrderedDictionary AppSettings
            {
                get
                {
                    return m_AppSettings;
                }
            }
    
            public OrderedDictionary ConnectionStrings
            {
                get
                {
                    return m_ConnectionStrings;
                }
            }
            #endregion
            #region "Constructors"
            /// <summary>
            /// Default constructor - declared private so that you can't instantiate an empty ConfigFile object
            /// <code>ConfigFile cfg = new ConfigFile()</code> will result in a NotImplemented exception
            /// </summary>
            private ConfigFile()
            {
                throw new NotImplementedException("No default constructor for the ConfigFile class");
            }
            /// <summary>
            /// Public constructor
            /// <example>ConfigFile cfg = new ConfigFile(@"c:\MyApp\MyApp.exe.config");</example>
            /// </summary>
            /// <param name="ConfigFilePath">The path to the configuration file</param>
            public ConfigFile(string ConfigFilePath)
            {
                //Check to see if the file exists
                if (File.Exists(ConfigFilePath)){
                    //Initialise the XmlDocument to hold the config file
                    m_XmlDoc = new XmlDocument();
                    //Store the path to the config file
                    m_ConfigFilePath = ConfigFilePath;
    
                    //FileStream to get the contents out of the file
                    fIn = new FileStream(m_ConfigFilePath, FileMode.Open, FileAccess.ReadWrite);
                    //StreamReader to read the FileStream
                    sr = new StreamReader(fIn);
                    //StreamWriter to write to the FileStream
                    sw = new StreamWriter(fIn);
    
                    //Try and load the XML from the file stream
                    try
                    {
                        m_XmlDoc.LoadXml(sr.ReadToEnd());
                        m_AppSettingsNode = m_XmlDoc.GetElementsByTagName("appSettings")[0];
                        m_ConnectionStringsNode = m_XmlDoc.GetElementsByTagName("connectionStrings")[0];
    
                        loadAppSettings();
                        loadConnStrings();
    
                    }
                    catch (Exception ex)
                    {
                        //If it went pear shaped, throw the exception upwards
                        throw ex;
                    }
    
                }
                else
                //If the file doesn't exist, throw a FileNotFound exception
                {
                    throw new FileNotFoundException(ConfigFilePath + " does not exist");
                }
            }
            #endregion
    
            private void loadAppSettings()
            {
                m_AppSettings = new OrderedDictionary();
                XmlNodeList nl = m_AppSettingsNode.SelectNodes("add");
                foreach (XmlNode node in nl)
                {
                    m_AppSettings.Add(node.Attributes["key"].Value, node.Attributes["value"].Value);
                }
            }
    
            private void loadConnStrings()
            {
                m_ConnectionStrings = new OrderedDictionary();
    
                XmlNodeList nl = m_ConnectionStringsNode.SelectNodes("add");
                foreach (XmlNode node in nl)
                {
                    m_ConnectionStrings.Add(node.Attributes["name"].Value, node.Attributes["connectionString"].Value);
                }
            }
    
            public void setAppSetting(string name, string newValue)
            {
                if (!m_AppSettings.Contains(name))
                {
                    throw new Exception(String.Format("Setting {0} does not exist in {1}", name, m_ConfigFilePath));
                }
                else
                {
                    m_AppSettings[name] = newValue;
                    m_XmlDoc.SelectSingleNode(String.Format(@"//appSettings/add[@key='{0}']",name)).Attributes["value"].Value = newValue;
                    fIn.SetLength(0);
                    sw.Write(m_XmlDoc.InnerXml);
                    sw.Flush();
                }
    
            }
            #region "Static Methods"
            /// <summary>
            /// Static method to return a ConfigFile object
            /// <example>ConfigFile cfg = ConfigFile.LoadConfigFile(@c:\MyApp\MyApp.exe.config");"</example>
            /// </summary>
            /// <param name="ConfigFilePath">Path to the configuration file to load</param>
            /// <returns></returns>
            public static ConfigFile LoadConfigFile(string ConfigFilePath)
            {
                return new ConfigFile(ConfigFilePath);
            }
            #endregion
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm working with an upstream system that sometimes sends me text destined for HTML/XML
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have thousands of HTML files to process using Groovy/Java and I need to
I have a reasonable size flat file database of text documents mostly saved in
I am trying to loop through a bunch of documents I have to put
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have a bunch of posts stored in text files formatted in yaml/textile (from
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has

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.