ConfigurationElement.LockItem Property
.NET Framework (current version)
Gets or sets a value indicating whether the element is locked.
Assembly: System.Configuration (in System.Configuration.dll)
Property Value
Type: System.Booleantrue if the element is locked; otherwise, false. The default is false.
| Exception | Condition |
|---|---|
| ConfigurationErrorsException | The element has already been locked at a higher configuration level. |
Use the LockItem property if you want to put a general lock on the element itself and its child elements.
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
.NET Framework
Available since 2.0
Available since 2.0
Show: