This documentation is archived and is not being maintained.

ConfigurationManager.OpenMappedExeConfiguration Method

Opens the specified client configuration file as a Configuration object that uses 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
Not applicable.

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.

Exception typeCondition

ConfigurationErrorsException

A configuration file could not be loaded.

The ConfigurationUserLevel object determines the location of the configuration file being opened. It indicates whether the file 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).

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.

The following code example shows how to use the OpenMappedExeConfiguration method to obtain all sections that are contained by the configuration file.

// Show how to use OpenMappedExeConfiguration.
static void DisplayMappedExeConfigurationFileSections()
{
    // Get the application configuration file path.
    string exeFilePath = System.IO.Path.Combine(
        Environment.CurrentDirectory, "ConfigurationManager.exe.config");

    // Map to the application configuration file.
    ExeConfigurationFileMap configFile = new ExeConfigurationFileMap();
    configFile.ExeConfigFilename = exeFilePath;
    Configuration config =
        ConfigurationManager.OpenMappedExeConfiguration(configFile, 
        ConfigurationUserLevel.None);

    // 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
Show: