人生是一场不能存盘的RPG,我只能尽量多搞几个Screenshot

March 21, 2007

Using Configuration.Section to access subsection

Filed under: .NET, Code snippets

Using Configuration.Section to access subsection
Copy from http://geekswithblogs.net/mnf/archive/2006/05/12/77981.aspx

I have a section in Web.Config:

<applicationSettings>

<FSBsnsCsLib.Properties.Settings>

</FSBsnsCsLib.Properties.Settings>

</applicationSettings>

I’ve tried to access inner section using shortcut “Section/Subsection”

string sSectionName=”applicationSettings/FSBusinessLib.My.MySettings”;
System.Configuration.ClientSettingsSection sectSettings = (ClientSettingsSection)config.Sections[sSectionName];

but it returned null.

The correct way is the following:

conststringcnstApplicationSection = “applicationSettings”;
ConfigurationSectionGroupgrpApplicationSection = config.SectionGroups[cnstApplicationSection];
string sSectionName=”FSBusinessLib.My.MySettings”;
System.Configuration.ClientSettingsSection sectSettings = grpApplicationSection .Sections[sSectionName];

Comments »

The URI to TrackBack this entry is: http://recordsome.blogsome.com/2007/03/21/using-configurationsection-to-access-subsection/trackback/

No comments yet.

RSS feed for comments on this post.

Leave a comment

Line and paragraph breaks automatic, e-mail address never displayed, HTML allowed: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <code> <em> <i> <strike> <strong>



Anti-spam measure: please retype the above text into the box provided.






















Get free blog up and running in minutes with Blogsome
Theme designed by Hadley Wickham