public string Url { get { return (string)this["url"]; } set { this["url"] = value;
}
}
}
I want a format like the one I've defined in web.config file. 'Company' and 'File' nodes should be siblings and extraction of nodes will be conditional dependent on companyname like
We can use ConfigurationManager.GetSection method to retrieve a specified configuration section for the current application's default configuration. You can create custom configuration sections using ConfigurationSection,
AppSettingsSection appSettingSection = (AppSettingsSection)config.GetSection(sectionName); // Get the AppSettings section.
Here are some related reference for your information:
MSDN Community Support
Please remember to click "Mark as Answer" the responses that resolved your issue.
If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.
Member
1 Points
74 Posts
Section may appear only once in Web.Config File
Oct 20, 2013 07:12 AM|uroosa|LINK
Hello,
I want to define more than one section inside sectionGroup.Its my config section
<configSections>
<sectionGroup name="CredentialsGroup">
<section name="Credentials"
type="CustomConfiguration.CredentialsSection"
allowDefinition="Everywhere"
allowLocation="true"
/>
</sectionGroup>
</configSections>
I have this format of section
<CredentialsGroup>
<Credentials>
<company name="Carolina" userid="abc" password="abc"></company>
<file name="dfbf0f94-767e-4c71-b4ee-2dc05fb76e3c.csv"
url="https://e.brightree.net/Home/Filecsv"></file>
<company name="Asbury" userid="dd" password="dd"></company>
<file name="dfbf0f94-767e-4c71-b4ee-2dc05fb76e3c.csv"
url="https://e.brightree.net/Home/File.csv"></file>
</Credentials>
</CredentialsGroup>
and this is my customconfiguration class
public class CredentialsSection: ConfigurationSection
{
[ConfigurationProperty("company",IsRequired=true)]
public CompanyElement Company
{
get {
return (CompanyElement)this["company"];
}
set
{
this["company"] = value;
}
}
[ConfigurationProperty("file",IsRequired=true)]
public FileElement File
{
get
{
return (FileElement)this["file"];
}
set
{
this["file"] = value;
}
}
}
public class CompanyElement : ConfigurationElement
{
[ConfigurationProperty("name",IsRequired=true)]
public string Name
{
get {
return (string)this["name"];
}
set
{
this["name"] = value;
}
}
[ConfigurationProperty("userid", IsRequired = true)]
public string UserId
{
get
{
return (string)this["userid"];
}
set
{
this["userid"] = value;
}
}
[ConfigurationProperty("password", IsRequired = true)]
public string Password
{
get
{
return (string)this["password"];
}
set
{
this["password"] = value;
}
}
}
public class FileElement : ConfigurationElement
{
[ConfigurationProperty("name", IsRequired = true)]
public string Name
{
get
{
return (string)this["name"];
}
set
{
this["name"] = value;
}
}
[ConfigurationProperty("url",IsRequired=true)]
public string Url
{
get
{
return (string)this["url"];
}
set {
this["url"] = value;
}
}
}
I want a format like the one I've defined in web.config file. 'Company' and 'File' nodes should be siblings and extraction of nodes will be conditional dependent on companyname like
ConfigurationManager.GetSection("CredentialsGroup/Credentials/company['name']=" + companyName);
but its not allowing me to define multiple section...Please Help
All-Star
32817 Points
3815 Posts
Re: Section may appear only once in Web.Config File
Oct 21, 2013 11:05 PM|Angie xu - MSFT|LINK
Hi uroosa
We can use ConfigurationManager.GetSection method to retrieve a specified configuration section for the current application's default configuration. You can create custom configuration sections using ConfigurationSection,
AppSettingsSection appSettingSection = (AppSettingsSection)config.GetSection(sectionName); // Get the AppSettings section.
Here are some related reference for your information:
# ConfigurationManager.GetSection Method
http://msdn.microsoft.com/en-us/library/system.configuration.configurationmanager.getsection(v=vs.110).aspx
# How to: Create Custom Configuration Sections Using ConfigurationSection
http://msdn.microsoft.com/en-us/library/2tw134k3.aspx
hope it helps,
Regards
Please remember to click "Mark as Answer" the responses that resolved your issue.
If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.