ConfigurationUserLevel ConfigurationUserLevel ConfigurationUserLevel ConfigurationUserLevel Enum

定義

構成オブジェクトで表される構成ファイルを指定するために使用されます。Used to specify which configuration file is to be represented by the Configuration object.

public enum class ConfigurationUserLevel
public enum ConfigurationUserLevel
type ConfigurationUserLevel = 
Public Enum ConfigurationUserLevel
継承
ConfigurationUserLevelConfigurationUserLevelConfigurationUserLevelConfigurationUserLevel

フィールド

None None None None 0

すべてのユーザーに適用する Configuration を取得します。Gets the Configuration that applies to all users.

PerUserRoaming PerUserRoaming PerUserRoaming PerUserRoaming 10

現在のユーザーに適用するローミング Configuration を取得します。Gets the roaming Configuration that applies to the current user.

PerUserRoamingAndLocal PerUserRoamingAndLocal PerUserRoamingAndLocal PerUserRoamingAndLocal 20

現在のユーザーに適用するローカル Configuration を取得します。Gets the local Configuration that applies to the current user.

次の例は、列挙型のConfigurationUserLevel使用方法を示しています。The following example shows how to use the ConfigurationUserLevel enumeration.


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Configuration;
using System.Collections;
using System.Collections.Specialized;
using System.Diagnostics;
using System.Text;


public class UsingConsoleConfigElement
{

    static void GetConfigurationFile()
    {

        try
        {
            // Get the current application configuration file.
            Configuration config =
              ConfigurationManager.OpenExeConfiguration(
               ConfigurationUserLevel.None);

            Console.WriteLine(config.FilePath);

        }
        catch (ConfigurationErrorsException e)
        {
            Console.WriteLine("[Exception error: {0}]",
                e.ToString());
        }


    }

    // Get the roaming configuration file associated 
    // with the current user.
    static void GetRoamingConfigurationFile()
    {


        try
        {
            // Get the roaming configuration 
            // that applies to the current user.
            Configuration roamingConfig =
              ConfigurationManager.OpenExeConfiguration(
               ConfigurationUserLevel.PerUserRoaming);

            Console.WriteLine(roamingConfig.FilePath);

        }
        catch (ConfigurationErrorsException e)
        {
            Console.WriteLine("[Exception error: {0}]",
                e.ToString());
        }


    }

    static void Main(string[] args)
    {
        Console.Write("Roaming configuration file: ");
        GetRoamingConfigurationFile();
        Console.WriteLine();
        Console.Write("Configuration file: ");
        GetConfigurationFile();
        Console.WriteLine("Enter any key to exit");
        Console.ReadLine();
    }
}

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

注釈

ConfigurationUserLevelによってConfigurationManager.OpenExeConfiguration返される構成オブジェクトによって表される構成ファイルを指定WebConfigurationManager.OpenMachineConfigurationするには、を使用します。Use ConfigurationUserLevel to specify which configuration file is to be represented by the Configuration object returned by ConfigurationManager.OpenExeConfiguration and WebConfigurationManager.OpenMachineConfiguration.

アプリケーション構成ファイルはアプリケーションと同じディレクトリにあり、同じ名前ですが、拡張子は .config です。Application configuration files are in the same directory as the application and have the same name, but with a .config extension. たとえば、C:\System\Public.exe の構成ファイルは C:\System\Public.exe.config. です。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.

適用対象

こちらもご覧ください