Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
RefreshSection Method

ConfigurationManager.RefreshSection Method

Note: This method is new in the .NET Framework version 2.0.

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

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

public static void RefreshSection (
	string sectionName
)
public static void RefreshSection (
	String sectionName
)
public static function RefreshSection (
	sectionName : String
)

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.

// Set appSettings.
static void SetAppSettings(bool refresh)
{
    // Get the machine.config file.
    System.Configuration.Configuration config =
            ConfigurationManager.OpenExeConfiguration(
            ConfigurationUserLevel.None);

    int appStgCnt = ConfigurationManager.AppSettings.Count;
    string asName = "AppSetting" + appStgCnt.ToString();

    config.AppSettings.Settings.Add(asName,
        DateTime.Now.ToLongDateString() + " " +
        DateTime.Now.ToLongTimeString());

    
    // Save the configuration file.
    config.Save(ConfigurationSaveMode.Modified);

    // Refresh the appSettings section so the secction
    // is read from the disk and not from the cache when
    // requested, next time.
    if (refresh)
        ConfigurationManager.RefreshSection("AppSettings");

    GetAppSettings();


Windows 98, Windows 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 .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.

.NET Framework

Supported in: 2.0

Community Additions

ADD
Show:
© 2015 Microsoft