CSharpTest.Net
Add Method
See Also  Example Send Feedback Download Help File
CSharpTest.Net.Library Assembly > CSharpTest.Net.AppConfig Namespace > UserSettingsSubSectionCollection Class : Add Method

name

Glossary Item Box

Adds a new section with the specified name

Syntax

Visual Basic (Declaration) 
Public Function Add( _
   ByVal name As String _
) As UserSettingsSubSection
C# 
public UserSettingsSubSection Add( 
   string name
)

Parameters

name

Example

Library/Library.Test/TestUserSettings.cs

C#Copy Code
Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.PerUserRoamingAndLocal);
UserSettingsSection section = UserSettingsSection.UserSettingsFrom(config);

section["a"] = "b";

UserSettingsSubSection sec2;
if (null == (sec2 = section.Sections["test.child"]))
    sec2 = section.Sections.Add("test.child");

sec2["a"] = "test.child.b";

config.Save();

UserSettingStorage store = new UserSettingStorage();

string value;
Assert.IsTrue(store.Read("test.child", "a", out value));
Assert.AreEqual("test.child.b", value);

Assert.IsTrue(store.Read("test.child", "a", out value));
Assert.AreEqual("test.child.b", value);
VB.NETCopy Code
Dim config As Configuration = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.PerUserRoamingAndLocal)
Dim section As UserSettingsSection = UserSettingsSection.UserSettingsFrom(config)

section("a") = "b"

Dim sec2 As UserSettingsSubSection
If Nothing = (sec2 = section.Sections("test.child")) Then
    sec2 = section.Sections.Add("test.child")
End If

sec2("a") = "test.child.b"

config.Save()

Dim store As New UserSettingStorage()

Dim value As String
Assert.IsTrue(store.Read("test.child", "a", value))
Assert.AreEqual("test.child.b", value)

Assert.IsTrue(store.Read("test.child", "a", value))
Assert.AreEqual("test.child.b", value)

Requirements

Target Platforms: Windows XP, Windows Server 2003, Windows Vista, Windows Server 2008, Windows 7

See Also

Generated with Document! X 2011 by Innovasys