dinu
dinu

Reputation: 33

How to check the particular section or key word exist in appconfig file

I have added my own section <section listeners> in my app.config file.

How can I check, programmatically, if the new section exist?

Upvotes: 0

Views: 2230

Answers (3)

maiconmm
maiconmm

Reputation: 311

You have to access it like a normal XML file.

        var config = XDocument.Load("App.Config");
        var element = config
            .Element("section");
        ...

Upvotes: 0

Eben Roux
Eben Roux

Reputation: 13256

section = ConfigurationManager.GetSection("sectionName") as SectionType

section will be null if the section isn't there.

Upvotes: 2

Andreas &#197;gren
Andreas &#197;gren

Reputation: 3929

You might want to have a look at How to: Create Custom Configuration Sections Using ConfigurationSection

Upvotes: 0

Related Questions