.NET Framework Class Library
ConfigurationElementLockItem Property

Gets or sets a value indicating whether the element is locked.

Namespace:   System.Configuration
Assembly:  System.Configuration (in System.Configuration.dll)
Syntax
Public Property LockItem As [%$TOPIC/ms134150_en-us_VS_110_1_0_0_0_0%]
public [%$TOPIC/ms134150_en-us_VS_110_1_0_1_0_0%] LockItem { get; set; }
public:
property [%$TOPIC/ms134150_en-us_VS_110_1_0_2_0_0%] LockItem {
	[%$TOPIC/ms134150_en-us_VS_110_1_0_2_0_1%] get ();
	void set ([%$TOPIC/ms134150_en-us_VS_110_1_0_2_0_2%] value);
}
member LockItem : [%$TOPIC/ms134150_en-us_VS_110_1_0_3_0_0%] with get, set

Property Value

Type: SystemBoolean
true if the element is locked; otherwise, false. The default is false.
Exceptions
ExceptionCondition
ConfigurationErrorsException

The element has already been locked at a higher configuration level.

Remarks

Use the LockItem property if you want to put a general lock on the element itself and its child elements.

Examples

The following example shows how to use the LockItem.

    ' Show how to set LockItem 
    ' It adds a new UrlConfigElement to  
    ' the collection. 
    Shared Sub LockItem()
        Dim name As String = "Contoso" 
        Dim url As String = "http://www.contoso.com/" 
        Dim port As Integer = 8080

        Try 
            ' Get the current configuration file. 
            Dim config _
            As System.Configuration.Configuration = _
            ConfigurationManager.OpenExeConfiguration( _
            ConfigurationUserLevel.None)

            ' Get the MyUrls section. 
            Dim myUrls As UrlsSection = _
            config.Sections("MyUrls")


            ' Create the new  element. 
            Dim newElement _
            As New UrlConfigElement(name, url, port)

            ' Set its lock.
            newElement.LockItem = True 

            ' Save the new element to the  
            ' configuration file. 
            If Not myUrls.ElementInformation.IsLocked Then

                myUrls.Urls.Add(newElement)

                config.Save(ConfigurationSaveMode.Full)

                ' This is used to obsolete the cached  
                ' section and read the updared version  
                ' from the configuration file.
                ConfigurationManager.RefreshSection("MyUrls")
            Else
                Console.WriteLine("Section was locked, could not update.")
            End If 

        Catch e As ConfigurationErrorsException
            Console.WriteLine("[LockItem: {0}]", _
            e.ToString())
        End Try 

    End Sub 'LockItem
// Show how to set LockItem 
// It adds a new UrlConfigElement to  
// the collection. 
static void LockItem()
{
    string name = "Contoso";
    string url = "http://www.contoso.com/";
    int port = 8080;

    try
    {
        // Get the current configuration file.
        System.Configuration.Configuration config =
            ConfigurationManager.OpenExeConfiguration(
            ConfigurationUserLevel.None);

        // Get the MyUrls section.
        UrlsSection myUrls =
           config.Sections["MyUrls"] as UrlsSection;


        // Create the new  element.
        UrlConfigElement newElement =
            new UrlConfigElement(name, url, port);

        // Set its lock.
        newElement.LockItem = true;

        // Save the new element to the  
        // configuration file. 
        if (!myUrls.ElementInformation.IsLocked)
        {

            myUrls.Urls.Add(newElement);

            config.Save(ConfigurationSaveMode.Full);

            // This is used to obsolete the cached  
            // section and read the updated  
            // bersion from the configuration file.
            ConfigurationManager.RefreshSection("MyUrls");
        }
        else
            Console.WriteLine(
                "Section was locked, could not update.");

    }
    catch (ConfigurationErrorsException e)
    {
        Console.WriteLine("[LockItem: {0}]",
            e.ToString());
    }

}
Version Information

.NET Framework

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

.NET Framework Client Profile

Supported in: 4, 3.5 SP1
Platforms

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.