ConfigurationManager.OpenMappedMachineConfiguration Method (ConfigurationFileMap)


The .NET API Reference documentation has a new home. Visit the .NET API Browser on to see the new experience.

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


Type: System.Configuration.ConfigurationFileMap

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

Exception Condition

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:



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.

// Access the machine configuration file using mapping.
// The function uses the OpenMappedMachineConfiguration 
// method to access the machine configuration. 
public static void MapMachineConfiguration()
  // Get the machine.config file.
  Configuration machineConfig =
  // Get the machine.config file path.
  ConfigurationFileMap configFile =
    new ConfigurationFileMap(machineConfig.FilePath);

  // Map the application configuration file to the machine 
  // configuration file.
  Configuration config =

  // Get the AppSettings section.
  AppSettingsSection appSettingSection =
  appSettingSection.SectionInformation.AllowExeDefinition =

  // Display the configuration file sections.
  ConfigurationSectionCollection sections = 

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

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


.NET Framework
Available since 2.0
Return to top