本文整理汇总了VB.NET中System.Configuration.ConfigurationManager.OpenMappedExeConfiguration方法的典型用法代码示例。如果您正苦于以下问题:VB.NET ConfigurationManager.OpenMappedExeConfiguration方法的具体用法?VB.NET ConfigurationManager.OpenMappedExeConfiguration怎么用?VB.NET ConfigurationManager.OpenMappedExeConfiguration使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。
在下文中一共展示了ConfigurationManager.OpenMappedExeConfiguration方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的VB.NET代码示例。
示例1: MapExeConfiguration
' Access a configuration file using mapping.
' This function uses the OpenMappedExeConfiguration
' method to access a new configuration file.
' It also gets the custom ConsoleSection and
' sets its ConsoleElement BackgroundColor and
' ForegroundColor properties to green and red
' respectively. Then it uses these properties to
' set the console colors.
Public Shared Sub MapExeConfiguration()
' Get the application configuration file.
Dim config As System.Configuration.Configuration = _
ConfigurationManager.OpenExeConfiguration( _
ConfigurationUserLevel.None)
Console.WriteLine(config.FilePath)
If config Is Nothing Then
Console.WriteLine( _
"The configuration file does not exist.")
Console.WriteLine( _
"Use OpenExeConfiguration to create file.")
End If
' Create a new configuration file by saving
' the application configuration to a new file.
Dim appName As String = _
Environment.GetCommandLineArgs()(0)
Dim configFile As String = _
String.Concat(appName, "2.config")
config.SaveAs(configFile, _
ConfigurationSaveMode.Full)
' Map the new configuration file.
Dim configFileMap As New ExeConfigurationFileMap()
configFileMap.ExeConfigFilename = configFile
' Get the mapped configuration file
config = _
ConfigurationManager.OpenMappedExeConfiguration( _
configFileMap, ConfigurationUserLevel.None)
' Make changes to the new configuration file.
' This is to show that this file is the
' one that is used.
Dim sectionName As String = "consoleSection"
Dim customSection As ConsoleSection = _
DirectCast(config.GetSection(sectionName), _
ConsoleSection)
If customSection Is Nothing Then
customSection = New ConsoleSection()
config.Sections.Add(sectionName, customSection)
End If
' Change the section configuration values.
customSection = _
DirectCast(config.GetSection(sectionName), _
ConsoleSection)
customSection.ConsoleElement.BackgroundColor = _
ConsoleColor.Green
customSection.ConsoleElement.ForegroundColor = _
ConsoleColor.Red
' Save the configuration file.
config.Save(ConfigurationSaveMode.Modified)
' Force a reload of the changed section. This
' makes the new values available for reading.
ConfigurationManager.RefreshSection(sectionName)
' Set console properties using the
' configuration values contained in the
' new configuration file.
Console.BackgroundColor = _
customSection.ConsoleElement.BackgroundColor
Console.ForegroundColor = _
customSection.ConsoleElement.ForegroundColor
Console.Clear()
Console.WriteLine()
Console.WriteLine( _
"Using OpenMappedExeConfiguration.")
Console.WriteLine( _
"Configuration file is: {0}", config.FilePath)
End Sub
开发者ID:VB.NET开发者,项目名称:System.Configuration,代码行数:87,代码来源:ConfigurationManager.OpenMappedExeConfiguration