Export (0) Print
Expand All

ConfigurationManager.OpenMappedExeConfiguration Method

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)

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



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


The ConfigurationUserLevel object for which you are opening the configuration.

Return Value

A Configuration object.

Exception typeCondition


A configuration file could not be loaded.

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).


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.
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 = 
    System.Configuration.Configuration config =

    // Loop to get the sections. Display basic information.
    Console.WriteLine("Name, Allow Definition");
    int i = 0;
    foreach (ConfigurationSection section in config.Sections)
            section.SectionInformation.Name + "\t" +
        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

Community Additions

© 2015 Microsoft