locked
Reading Config file RRS feed

  • Question

  • User-541003552 posted

    Hello All,

    I have an external .config file. How can i read that file and makes changes to value in some of the "Add" tags in the AppSettings.

    Any help or sample code.

    Thanks

    Thursday, December 18, 2014 6:42 AM

Answers

  • User-760709272 posted

    Config files are just xml documents so load them into an instance of XmlDocument, find the nodes you want using SelectSingleNode and update as normal then save.  There is nothing special about config files.

    However config is supposed to be read-only, if you are making dynamic updates to the config file from your code you shouldn't be using appsettings in the first place, use something else like a database.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, December 18, 2014 6:46 AM
  • User61956409 posted

    Hi KeeEdwins,

    Thanks for your post.

    As for your problem, you could refer to this post which shows how to update (add, edit or remove) AppSettings and custom config sections.

    Hope it will be helpful to you.

    Best Regards,

    Fei Han

    This response contains a reference to a third party World Wide Web site. Microsoft is providing this information as a convenience to you. Microsoft does not control these sites and has not tested any software or information found on these sites; therefore, Microsoft cannot make any representations regarding the quality, safety, or suitability of any software or information found there. There are inherent dangers in the use of any software found on the Internet, and Microsoft cautions you to make sure that you completely understand the risk before retrieving any software from the Internet.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, December 18, 2014 10:34 PM

All replies

  • User-760709272 posted

    Config files are just xml documents so load them into an instance of XmlDocument, find the nodes you want using SelectSingleNode and update as normal then save.  There is nothing special about config files.

    However config is supposed to be read-only, if you are making dynamic updates to the config file from your code you shouldn't be using appsettings in the first place, use something else like a database.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, December 18, 2014 6:46 AM
  • User61956409 posted

    Hi KeeEdwins,

    Thanks for your post.

    As for your problem, you could refer to this post which shows how to update (add, edit or remove) AppSettings and custom config sections.

    Hope it will be helpful to you.

    Best Regards,

    Fei Han

    This response contains a reference to a third party World Wide Web site. Microsoft is providing this information as a convenience to you. Microsoft does not control these sites and has not tested any software or information found on these sites; therefore, Microsoft cannot make any representations regarding the quality, safety, or suitability of any software or information found there. There are inherent dangers in the use of any software found on the Internet, and Microsoft cautions you to make sure that you completely understand the risk before retrieving any software from the Internet.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, December 18, 2014 10:34 PM