ConfigurationSectionCollection.Add(String, ConfigurationSection) Method
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Adds a ConfigurationSection object to the ConfigurationSectionCollection object.
public:
void Add(System::String ^ name, System::Configuration::ConfigurationSection ^ section);
public void Add (string name, System.Configuration.ConfigurationSection section);
member this.Add : string * System.Configuration.ConfigurationSection -> unit
Public Sub Add (name As String, section As ConfigurationSection)
Parameters
- name
- String
The name of the section to be added.
- section
- ConfigurationSection
The section to be added.
Examples
The following example shows how to use the Add method.
static void AddSection()
{
try
{
System.Configuration.Configuration config =
ConfigurationManager.OpenExeConfiguration(
ConfigurationUserLevel.None);
CustomSection customSection =
new CustomSection();
string index =
config.Sections.Count.ToString();
customSection.FileName =
"newFile" + index + ".txt";
string sectionName = "CustomSection" + index;
TimeSpan ts = new TimeSpan(0, 15, 0);
customSection.MaxIdleTime = ts;
customSection.MaxUsers = 100;
config.Sections.Add(sectionName, customSection);
customSection.SectionInformation.ForceSave = true;
config.Save(ConfigurationSaveMode.Full);
}
catch (ConfigurationErrorsException err)
{
Console.WriteLine(err.ToString());
}
}
Shared Sub AddSection()
Try
Dim config _
As System.Configuration.Configuration = _
ConfigurationManager.OpenExeConfiguration( _
ConfigurationUserLevel.None)
Dim customSection _
As New CustomSection()
Dim index As String = _
config.Sections.Count.ToString()
customSection.FileName = _
"newFile" + index + ".txt"
Dim sectionName As String = _
"CustomSection" + index
Dim ts As New TimeSpan(0, 15, 0)
customSection.MaxIdleTime = ts
customSection.MaxUsers = 100
config.Sections.Add(sectionName, customSection)
customSection.SectionInformation.ForceSave = True
config.Save(ConfigurationSaveMode.Full)
Catch err As ConfigurationErrorsException
Console.WriteLine(err.ToString())
End Try
End Sub
Remarks
By default, this method adds the specified ConfigurationSection object if it is not already contained within the collection.
Applies to
See also
Col·laboreu amb nosaltres a GitHub
La font d'aquest contingut es pot trobar al GitHub, on també podeu crear i revisar problemes i sol·licituds d'extracció. Per obtenir més informació, consulteu la nostra guia per a col·laboradors.