本文整理汇总了C#中System.Configuration.ConfigurationElement.LockItem属性的典型用法代码示例。如果您正苦于以下问题:C# ConfigurationElement.LockItem属性的具体用法?C# ConfigurationElement.LockItem怎么用?C# ConfigurationElement.LockItem使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类System.Configuration.ConfigurationElement
的用法示例。
在下文中一共展示了ConfigurationElement.LockItem属性的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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());
}
}