ConfigurationUserLevel Enumeration

 

Used to specify which configuration file is to be represented by the Configuration object.

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

Public Enumeration ConfigurationUserLevel

Member nameDescription
None

Get the Configuration that applies to all users.

PerUserRoaming

Get the roaming Configuration that applies to the current user.

PerUserRoamingAndLocal

Get the local Configuration that applies to the current user.

Use ConfigurationUserLevel to specify which configuration file is to be represented by the Configuration object returned by ConfigurationManager.OpenExeConfiguration and WebConfigurationManager.OpenMachineConfiguration.

Application configuration files are in the same directory as the application and have the same name, but with a .config extension. For example, the configuration file for C:\System\Public.exe is C:\System\Public.exe.config.

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 following example shows how to use the ConfigurationUserLevel enumeration.

Imports System
Imports System.Collections.Generic
Imports System.Linq
Imports System.Text
Imports System.Configuration
Imports System.Collections
Imports System.Collections.Specialized
Imports System.Diagnostics


Public Class UsingConsoleConfigElement

	Private Shared Sub GetConfigurationFile()

		Try
			' Get the current application configuration file.
            Dim config As Configuration = _
                ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None)

			Console.WriteLine(config.FilePath)

		Catch e As ConfigurationErrorsException
			Console.WriteLine("[Exception error: {0}]", e.ToString())
		End Try


	End Sub

	' Get the roaming configuration file associated 
	' with the current user.
	Private Shared Sub GetRoamingConfigurationFile()


	  Try
		  ' Get the roaming configuration 
		  ' that applies to the current user.
            Dim roamingConfig As Configuration = _
                ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.PerUserRoaming)

		  Console.WriteLine(roamingConfig.FilePath)

	  Catch e As ConfigurationErrorsException
		  Console.WriteLine("[Exception error: {0}]", e.ToString())
	  End Try


	End Sub


	Shared Sub Main(ByVal args() As String)
		Console.Write("Roaming configuration file: ")
			GetRoamingConfigurationFile()
			Console.WriteLine()
		Console.Write("Configuration file: ")
			GetConfigurationFile()
		Console.WriteLine("Enter any key to exit")
		Console.ReadLine()
	End Sub
End Class

.NET Framework
Available since 2.0
Return to top
Show: