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

ConfigurationElement.IsReadOnly Method

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

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 ()
public boolean IsReadOnly ()
public function IsReadOnly () : boolean

Return Value

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());
    



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