Dieser Artikel wurde maschinell übersetzt. Bewegen Sie den Mauszeiger über die Sätze im Artikel, um den Originaltext anzuzeigen. Weitere Informationen
Übersetzung
Original
Dieser Artikel wurde noch nicht bewertet - Dieses Thema bewerten.

ConfigurationElement.LockItem-Eigenschaft

Ruft einen Wert ab, der angibt, ob das Element gesperrt ist, oder legt diesen fest.

Namespace:  System.Configuration
Assembly:  System.Configuration (in System.Configuration.dll)
public bool LockItem { get; set; }

Eigenschaftswert

Typ: System.Boolean
true , wenn das Element gesperrt ist, andernfalls false. Die Standardeinstellung ist false.
AusnahmeBedingung
ConfigurationErrorsException

Das Element wurde bereits auf einer höheren Konfigurationsebene gesperrt.

Verwenden Sie die LockItem-Eigenschaft, wenn Sie das Element selbst sowie dessen untergeordnete Elemente allgemein sperren möchten.

Im folgenden Beispiel wird die Verwendung von LockItem veranschaulicht.


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

}


.NET Framework

Unterstützt in: 4.5, 4, 3.5, 3.0, 2.0

.NET Framework Client Profile

Unterstützt in: 4, 3.5 SP1

Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core-Rolle wird nicht unterstützt), Windows Server 2008 R2 (Server Core-Rolle wird mit SP1 oder höher unterstützt; Itanium wird nicht unterstützt)

.NET Framework unterstützt nicht alle Versionen sämtlicher Plattformen. Eine Liste der unterstützten Versionen finden Sie unter Systemanforderungen für .NET Framework.
Fanden Sie dies hilfreich?
(1500 verbleibende Zeichen)

Community-Beiträge

HINZUFÜGEN
© 2013 Microsoft. Alle Rechte vorbehalten.