SectionInformation.ForceSave Property


Gets or sets a value that indicates whether the associated configuration section will be saved even if it has not been modified.

Namespace:   System.Configuration
Assembly:  System.Configuration (in System.Configuration.dll)

Public Property ForceSave As Boolean

Property Value

Type: System.Boolean

true if the associated ConfigurationSection object will be saved even if it has not been modified; otherwise, false. The default is false.


If the configuration file is saved (even if there are no modifications), ASP.NET restarts the application.

The following example shows how to use the ForceSave property of a ConfigurationSection object.

' Create a section whose name is 
' MyUrls that contains a nested collection as 
' defined by the UrlsSection class.
Shared Sub CreateSection()
    Dim sectionName As String = "MyUrls"


        ' Get the current configuration file.
        Dim config _
        As System.Configuration.Configuration = _
        ConfigurationManager.OpenExeConfiguration( _

        Dim urlsSection As UrlsSection

        ' Create the section whose name
        ' attribute isMyUrls in 
        ' <configSections>.
        ' Also, create the related target section 
        ' MyUrls in <configuration>.
        If config.Sections(sectionName) Is Nothing Then
            urlsSection = New UrlsSection()

            ' Change the default values of 
            ' the simple element.
            urlsSection.Simple.Name = "Contoso"
            urlsSection.Simple.Url = ""
            urlsSection.Simple.Port = 8080

            config.Sections.Add(sectionName, urlsSection)
            urlsSection.SectionInformation.ForceSave = True
        End If
    Catch e As ConfigurationErrorsException
        Console.WriteLine("[CreateSection: {0}]", e.ToString())
    End Try

End Sub 'CreateSection

.NET Framework
Available since 2.0
Return to top