Export (0) Print
Expand All

ConfigurationElement.IsReadOnly Method

Gets a value indicating whether the ConfigurationElement object is read-only.

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

public virtual bool IsReadOnly()

Return Value

Type: System.Boolean
true if the ConfigurationElement object is read-only; otherwise, false.

The system defines configuration elements that cannot be modified.

To determine which elements can be modified, use the IsReadOnly method.

The following example shows how to use the IsReadOnly method. It is used on a custom section and returns false.

// Show how to use IsReadOnly. 
// It loops to see if the elements are read only.  
static void ReadOnlyElements()
{
    try
    {
        // Get the configuration file.
        System.Configuration.Configuration config =
            ConfigurationManager.OpenExeConfiguration(
            ConfigurationUserLevel.None);

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


        UrlsCollection elements = myUrlsSection.Urls;


        IEnumerator elemEnum =
            elements.GetEnumerator();

        int i = 0;
        Console.WriteLine(elements.Count.ToString());

        while (elemEnum.MoveNext())
        {
            Console.WriteLine("The element {0} is read only: {1}",
             elements[i].Name,
             elements[i].IsReadOnly().ToString());
            i += 1;
        }
    }
    catch (ConfigurationErrorsException err)
    {
        Console.WriteLine("[ReadOnlyElements: {0}]",
            err.ToString());
    }

}

.NET Framework

Supported in: 4.5, 4, 3.5, 3.0, 2.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

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

Show:
© 2014 Microsoft