Export (0) Print
Expand All

ConfigurationManager.OpenMappedMachineConfiguration Method

Opens the machine configuration file as a Configuration object that uses the specified file mapping.

Namespace: System.Configuration
Assembly: System.Configuration (in system.configuration.dll)

public static Configuration OpenMappedMachineConfiguration (
	ConfigurationFileMap fileMap
)
public static Configuration OpenMappedMachineConfiguration (
	ConfigurationFileMap fileMap
)
public static function OpenMappedMachineConfiguration (
	fileMap : ConfigurationFileMap
) : Configuration
Not applicable.

Parameters

fileMap

An ExeConfigurationFileMap object that references configuration file to use instead of the application default configuration file.

Return Value

A Configuration object.

Exception typeCondition

ConfigurationErrorsException

A configuration file could not be loaded.

Machine configuration settings apply to the whole computer and all applications that reside on it, unless overridden for the local application. Machine configuration settings are read from the Machine.config file of the currently running version of the .NET Framework. The Machine.config file is located in the following subdirectory:

%windir%\Microsoft.NET\Framework\version\config

NoteNote:

To obtain the Configuration object for a resource, your code must have read permissions on all the configuration files from which it inherits settings. To update a configuration file, your code must additionally have write permissions for both the configuration file and the directory in which it exists. It is not possible to access the Machine.config file for other versions of the .NET Framework that might be installed on the computer.

The following code example shows how to use the OpenMappedMachineConfiguration method to obtain all sections in the configuration file.

// Show how to use OpenMappedMachineConfiguration.
static void DisplayMappedMachineConfigurationFileSections()
{
    // Get the machine.config file.
    Configuration machineConfig =
        ConfigurationManager.OpenMachineConfiguration();

    // Map to the machine configuration file.
    ConfigurationFileMap configFile = 
        new ConfigurationFileMap(machineConfig.FilePath);
    Configuration config =
        ConfigurationManager.OpenMappedMachineConfiguration(configFile);

    // Display the configuration file sections.
    ConfigurationSectionCollection sections = config.Sections;

    Console.WriteLine();
    Console.WriteLine("Sections in machine.config:");

    // Loop to get the sections machine.config.
    foreach (ConfigurationSection section in sections)
    {
        string name = section.SectionInformation.Name;
        Console.WriteLine("Name: {0}", name);
    }

}

Windows 98, Windows Server 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 Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0

Community Additions

ADD
Show:
© 2015 Microsoft