Note: This method is new in the .NET Framework version 2.0.
Opens the specified client configuration file as a
Configuration object using the specified file mapping and user level.
Namespace: System.Configuration
Assembly: System.Configuration (in system.configuration.dll)
Visual Basic (Declaration)
Public Shared Function OpenMappedExeConfiguration ( _
fileMap As ExeConfigurationFileMap, _
userLevel As ConfigurationUserLevel _
) As Configuration
Dim fileMap As ExeConfigurationFileMap
Dim userLevel As ConfigurationUserLevel
Dim returnValue As Configuration
returnValue = ConfigurationManager.OpenMappedExeConfiguration(fileMap, userLevel)
public static Configuration OpenMappedExeConfiguration (
ExeConfigurationFileMap fileMap,
ConfigurationUserLevel userLevel
)
public:
static Configuration^ OpenMappedExeConfiguration (
ExeConfigurationFileMap^ fileMap,
ConfigurationUserLevel userLevel
)
public static Configuration OpenMappedExeConfiguration (
ExeConfigurationFileMap fileMap,
ConfigurationUserLevel userLevel
)
public static function OpenMappedExeConfiguration (
fileMap : ExeConfigurationFileMap,
userLevel : ConfigurationUserLevel
) : Configuration
Parameters
- fileMap
An ExeConfigurationFileMap object that references configuration file to use instead of the application default configuration file.
- userLevel
The ConfigurationUserLevel object for which you are opening the configuration.
Return Value
A Configuration object.
The ConfigurationUserLevel object determines the location of the configuration file being opened by indicating whether it has no user level (the configuration file is in the same directory as the application) or has a per-user level (the configuration file is in an application settings path determined by userLevel).
Note |
|---|
| To obtain the Configuration object for a resource, your code must have read privileges on all of the configuration files from which it inherits settings. To update a configuration file, your code must additionally have write privileges for both the configuration file and the directory in which it exists. |
The following code example shows how to use the OpenMappedExeConfiguration method to obtain all sections contained by the configuration file.
' Get all the sections in the mapped exe.config.
' Show how to use the
' GetMappedExeConfigurationSections(fileMap, userLevel) method.
Shared Sub GetMappedExeConfigurationSections()
' Get the machine.config file.
Dim fileMap As New ExeConfigurationFileMap()
' You may want to map to your own exe.comfig file here.
fileMap.ExeConfigFilename = _
"C:\test\ConfigurationManager.exe.config"
Dim config As System.Configuration.Configuration = _
ConfigurationManager.OpenMappedExeConfiguration(fileMap, _
ConfigurationUserLevel.None)
' Loop to get the sections. Display basic information.
Console.WriteLine("Name, Allow Definition")
Dim i As Integer = 0
Dim section As ConfigurationSection
For Each section In config.Sections
Console.WriteLine(( _
section.SectionInformation.Name + _
ControlChars.Tab + _
section.SectionInformation.AllowExeDefinition.ToString()))
i += 1
Next section
Console.WriteLine("[Total number of sections: {0]", i)
' Display machine.config path.
Console.WriteLine("[File path: {0]", config.FilePath)
End Sub 'GetMappedExeConfigurationSections
// Get all the sections in the mapped exe.config.
// Show how to use the
// GetMappedExeConfigurationSections(fileMap, userLevel) method.
static void GetMappedExeConfigurationSections()
{
// Get the machine.config file.
ExeConfigurationFileMap fileMap =
new ExeConfigurationFileMap();
// You may want to map to your own exe.comfig file here.
fileMap.ExeConfigFilename =
@"C:\test\ConfigurationManager.exe.config";
System.Configuration.Configuration config =
ConfigurationManager.OpenMappedExeConfiguration(fileMap,
ConfigurationUserLevel.None);
// Loop to get the sections. Display basic information.
Console.WriteLine("Name, Allow Definition");
int i = 0;
foreach (ConfigurationSection section in config.Sections)
{
Console.WriteLine(
section.SectionInformation.Name + "\t" +
section.SectionInformation.AllowExeDefinition);
i += 1;
Console.WriteLine("[Total number of sections: {0]", i);
// Display machine.config path.
Console.WriteLine("[File path: {0]", config.FilePath);
Windows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
The .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.
.NET Framework
Supported in: 2.0