.NET Framework Class Library
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.
Assembly: System.Configuration (in System.Configuration.dll)
Syntax
Visual Basic
Public Property ForceSave As Boolean Get Set
C#
public bool ForceSave { get; set; }
Visual C++
public: property bool ForceSave { bool get (); void set (bool value); }
F#
member ForceSave : bool with get, set
Property Value
Type: System.Booleantrue if the associated ConfigurationSection object will be saved even if it has not been modified; otherwise, false. The default is false.
Note |
|---|
If the configuration file is saved (even if there are no modifications), ASP.NET restarts the application. |
Examples
The following example shows how to use the ForceSave property of a ConfigurationSection object.
Visual Basic
' 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"
Try
' Get the current configuration file.
Dim config _
As System.Configuration.Configuration = _
ConfigurationManager.OpenExeConfiguration( _
ConfigurationUserLevel.None)
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 = "http://www.contoso.com"
urlsSection.Simple.Port = 8080
config.Sections.Add(sectionName, urlsSection)
urlsSection.SectionInformation.ForceSave = True
config.Save(ConfigurationSaveMode.Full)
End If
Catch e As ConfigurationErrorsException
Console.WriteLine("[CreateSection: {0}]", e.ToString())
End Try
End Sub 'CreateSection
C#
// Create a section whose name is // MyUrls that contains a nested collection as // defined by the UrlsSection class. static void CreateSection() { string sectionName = "MyUrls"; try { // Get the current configuration file. System.Configuration.Configuration config = ConfigurationManager.OpenExeConfiguration( ConfigurationUserLevel.None); UrlsSection urlsSection; // Create the section whose name attribute // is MyUrls in <configSections>. // Also, create the related target section // MyUrls in <configuration>. if (config.Sections[sectionName] == null) { urlsSection = new UrlsSection(); // Change the default values of // the simple element. urlsSection.Simple.Name = "Contoso"; urlsSection.Simple.Url = "http://www.contoso.com"; urlsSection.Simple.Port = 8080; config.Sections.Add(sectionName, urlsSection); urlsSection.SectionInformation.ForceSave = true; config.Save(ConfigurationSaveMode.Full); } } catch (ConfigurationErrorsException e) { Console.WriteLine("[CreateSection: {0}]", e.ToString()); } }
Version Information
.NET Framework
Supported in: 4, 3.5, 3.0, 2.0.NET Framework Client Profile
Supported in: 4, 3.5 SP1Platforms
Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2
The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
See Also
Note