c# - How to Load Config File Programmatically -


Assume that I have a custom config file that matches custom-defined configuration sections and config elements. These configurations are stored in class libraries.

The config file looks like this

  & lt ;? Xml version = "1.0" encoding = "UTF-8"? & Gt; & Lt; Schoool name = "RT" & gt; & Lt; Students & gt; & Lt; / Student & gt; & Lt; / Schoool & gt;  

How can I load and use this configured file from the program?

I do not want to use raw XML handling, but leverage the already defined config class

You have to customize it for your needs, but here's the code I use in one of my projects to do this:

  var fileMap = New Configure File Size ("Pathtoconfigfile"); Var Configuration = Configuration Manager OpenMapCache configuration (filemap); Var section group = configuration GetSectionGroup ("applicationSettings"); // This section is the name of the group, changes your requirements var section = (client setting) section group. Actions ("MyTarget.Namespace.Properties.Settings"); // This is the name of the section, changes in your settings var setting = section.Settings.Get ("SettingName"); // This setting is the name, the setting to return your needs. Value ValueXml.InnerText;  

Note that I am reading a valid .NET config file. I'm not using this code to read the config file of an EXE from a DLL. I'm not sure that This works with the example config file provided by you, but it should be a good start.


Comments

Popular posts from this blog

c++ - Linux and clipboard -

What is expire header and how to achive them in ASP.NET and PHP? -

sql server - How can I determine which of my SQL 2005 statistics are unused? -