This documentation is archived and is not being maintained.

ConfigurationElement.IsModified Method

Indicates whether this configuration element has been modified since it was last saved or loaded, when implemented in a derived class.

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

protected internal virtual bool IsModified()

Return Value

Type: System.Boolean
true if the element has been modified; otherwise, false.

The IsModified method determines whether this ConfigurationElement object will be written to the configuration file when the Save method is called. If the return value is false, it is assumed that the configuration file represents the current state of the element.

By default, IsModified returns true after a property is set through the indexer to this ConfigurationElement object.

Override the IsModified method to provide custom indication of the state of this ConfigurationElement element.

The following example shows how to extend IsModified.

protected override bool IsModified()
    bool ret = base.IsModified();
    // You can enter your custom processing code here. 
    return ret;

The method shown in the previous example is called when a configuration element is modified, as in the following example.

// Show how to use IsModified. 
// This method modifies the port property 
// of the url element named Microsoft and 
// saves the modification to the configuration 
// file. This in turn will cause the overriden 
// UrlConfigElement.IsModified() mathod to be called.  
static void ModifyElement()
        // Get the configuration file.
        System.Configuration.Configuration config =

        // Get the MyUrls section.
        UrlsSection myUrlsSection =
            config.GetSection("MyUrls") as UrlsSection;

        UrlsCollection elements = myUrlsSection.Urls;

        IEnumerator elemEnum =

        int i = 0;
        while (elemEnum.MoveNext())
            if (elements[i].Name == "Microsoft")
                elements[i].Port = 1010;
                bool readOnly = elements[i].IsReadOnly();
            i += 1;

        if (!myUrlsSection.ElementInformation.IsLocked)


            // This to obsolete the MyUrls cached  
            // section and read the updated version 
            // from the configuration file.
                "Section was locked, could not update.");

    catch (ConfigurationErrorsException err)
        Console.WriteLine("[ModifyElement: {0}]",


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

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

.NET Framework

Supported in: 3.5, 3.0, 2.0