Export (0) Print
Expand All

ConfigurationManager.RefreshSection Method

Refreshes the named section so the next time that it is retrieved it will be re-read from disk.

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

'Declaration
Public Shared Sub RefreshSection ( _
	sectionName As String _
)
'Usage
Dim sectionName As String

ConfigurationManager.RefreshSection(sectionName)
public static void RefreshSection (
	String sectionName
)
public static function RefreshSection (
	sectionName : String
)
Not applicable.

Parameters

sectionName

The configuration section name or the configuration path and section name of the section to refresh.

This method invalidates the cache for the specified configuration section without affecting other sections.

The following code example shows how to use the RefreshSection method to refresh the application settings configuration section.

' Show how to use OpenExeConfiguration(ConfigurationUserLevel) 
' and RefreshSection. 
Shared Sub UpdateAppSettings() 
    ' Get the configuration file.
    Dim config As System.Configuration.Configuration = _
    ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None)
    
    ' Add an entry to appSettings.
    Dim appStgCnt As Integer = _
    ConfigurationManager.AppSettings.Count
    Dim newKey As String = "NewKey" + appStgCnt.ToString()
    
    Dim newValue As String = DateTime.Now.ToLongDateString() + " " + _
    DateTime.Now.ToLongTimeString()
    
    config.AppSettings.Settings.Add(newKey, newValue)
    
    ' Save the configuration file.
    config.Save(ConfigurationSaveMode.Modified)
    
    ' Force a reload of the changed section.
    ConfigurationManager.RefreshSection("appSettings")

End Sub 'UpdateAppSettings
 

Windows 98, Windows Server 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0

Community Additions

ADD
Show:
© 2014 Microsoft