Valdas
Valdas

Reputation: 370

C# get whole raw XML from ConfigurationManager (not from the config file)

As title states, I need to get whole raw XML data from ConfigurationManager but I am unable to find a way to do it.

I tried SectionInformation.GetRawXml(); but I am getting error "This operation does not apply at runtime."

var section = ConfigurationManager.GetSection("system.serviceModel/client") as ClientSection;
var s = section.SectionInformation.GetRawXml();

I have a Gupta TD project that uses C# class library to communicate with a web service, and when I try to debug this project my app.config is not used. It works fine when I am executing the program directly, my guess is Gupta TD uses some kind of default configuration and I am unable to locate it, so reading app.config file is not an option, I need to get it from ConfigurationManager and thanks to Michael Randall hint I found it using AppDomain.CurrentDomain.SetupInformation.ConfigurationFile.

Upvotes: 0

Views: 1278

Answers (2)

TheGeneral
TheGeneral

Reputation: 81533

Just used the File.ReadAllText Method

File.ReadAllText("<MyApplicationName.exe>.config")

However it does beg the question why you want to do this.

you can use this to get the name of the ConfigurationFile

AppDomain.CurrentDomain.SetupInformation.ConfigurationFile

AppDomainSetup.ConfigurationFile Property

Upvotes: 2

Giorgi Kulijanishvili
Giorgi Kulijanishvili

Reputation: 11

You can read the whole config file as xml

XmlDocument xmlDoc = new XmlDocument();

xmlDoc.Load(Server.MapPath("~/file.config")); 

Upvotes: 1

Related Questions