ConfigurationManager.OpenExeConfiguration Method (String)

Opens the specified client configuration file as a Configuration object.

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

Public Shared Function OpenExeConfiguration ( _
	exePath As String _
) As Configuration
Dim exePath As String
Dim returnValue As Configuration

returnValue = ConfigurationManager.OpenExeConfiguration(exePath)
public static Configuration OpenExeConfiguration (
	String exePath
public static function OpenExeConfiguration (
	exePath : String
) : Configuration
Not applicable.



The path of the configuration file.

The configuration file resides in the same directory of the executable file.

Return Value

A Configuration object.

Exception typeCondition


A configuration file could not be loaded.

Client applications use a global configuration that applies to all users, separate configurations that apply to individual users, and configurations that apply to roaming users. The userLevel value determines the location of the configuration file being opened. It indicates 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 the user level type.).

Specify which configuration to obtain by passing one of the following values for the userLevel parameter:

  • To get the Configuration that applies to all users, set userLevel to None.

  • To get the local Configuration that applies to the current user, set userLevel to PerUserRoamingAndLocal.

  • To get the roaming Configuration that applies to the current user, set userLevel to PerUserRoaming.


    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 OpenExeConfiguration method.

' Show how to use OpenExeConfiguration(string).
Shared Sub DisplayAppSettingsRawXml() 
    ' Get the application path.
    Dim exePath As String = System.IO.Path.Combine( _
    Environment.CurrentDirectory, "ConfigurationManager.exe")
    ' Get the configuration file.
    Dim config As System.Configuration.Configuration = _
    ' Get the AppSetins section.
    Dim appSettingSection As AppSettingsSection = _
    ' Display raw xml.
    Console.WriteLine( _

End Sub 'DisplayAppSettingsRawXml

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