다음을 통해 공유


ConfigurationManager.OpenMappedExeConfiguration 메서드

정의

지정된 클라이언트 구성 파일을 Configuration 개체로 엽니다.

오버로드

OpenMappedExeConfiguration(ExeConfigurationFileMap, ConfigurationUserLevel)

지정된 파일 매핑 및 사용자 수준을 사용하여 지정된 클라이언트 구성 파일을 Configuration 개체로 엽니다.

OpenMappedExeConfiguration(ExeConfigurationFileMap, ConfigurationUserLevel, Boolean)

지정된 파일 매핑, 사용자 수준 및 미리 로드 옵션을 사용하여 지정된 클라이언트 구성 파일을 Configuration 개체로 엽니다.

OpenMappedExeConfiguration(ExeConfigurationFileMap, ConfigurationUserLevel)

Source:
ConfigurationManager.cs
Source:
ConfigurationManager.cs
Source:
ConfigurationManager.cs

지정된 파일 매핑 및 사용자 수준을 사용하여 지정된 클라이언트 구성 파일을 Configuration 개체로 엽니다.

public:
 static System::Configuration::Configuration ^ OpenMappedExeConfiguration(System::Configuration::ExeConfigurationFileMap ^ fileMap, System::Configuration::ConfigurationUserLevel userLevel);
public static System.Configuration.Configuration OpenMappedExeConfiguration (System.Configuration.ExeConfigurationFileMap fileMap, System.Configuration.ConfigurationUserLevel userLevel);
static member OpenMappedExeConfiguration : System.Configuration.ExeConfigurationFileMap * System.Configuration.ConfigurationUserLevel -> System.Configuration.Configuration
Public Shared Function OpenMappedExeConfiguration (fileMap As ExeConfigurationFileMap, userLevel As ConfigurationUserLevel) As Configuration

매개 변수

fileMap
ExeConfigurationFileMap

애플리케이션 기본 구성 파일 대신 사용할 구성 파일입니다.

userLevel
ConfigurationUserLevel

구성을 열 사용자 수준을 지정하는 열거형 값 중 하나입니다.

반환

구성 개체입니다.

예외

구성 파일을 로드할 수 없는 경우

예제

다음 코드 예제를 사용 하는 방법에 설명 합니다 OpenMappedExeConfiguration 구성 파일에 포함 된 모든 섹션을 가져오는 방법입니다.


   // Access a configuration file using mapping.
   // This function uses the OpenMappedExeConfiguration 
   // method to access a new configuration file.   
   // It also gets the custom ConsoleSection and 
   // sets its ConsoleElement BackgroundColor and
   // ForegroundColor properties to green and red
   // respectively. Then it uses these properties to
   // set the console colors.  
   public static void MapExeConfiguration()
   {

     // Get the application configuration file.
     System.Configuration.Configuration config =
       ConfigurationManager.OpenExeConfiguration(
             ConfigurationUserLevel.None);
   
     Console.WriteLine(config.FilePath);

     if (config == null)
     {
       Console.WriteLine(
         "The configuration file does not exist.");
       Console.WriteLine(
        "Use OpenExeConfiguration to create the file.");
     }

     // Create a new configuration file by saving 
     // the application configuration to a new file.
     string appName = 
       Environment.GetCommandLineArgs()[0];

     string configFile =  string.Concat(appName, 
       ".2.config");
     config.SaveAs(configFile, ConfigurationSaveMode.Full);

     // Map the new configuration file.
     ExeConfigurationFileMap configFileMap = 
         new ExeConfigurationFileMap();
     configFileMap.ExeConfigFilename = configFile;

     // Get the mapped configuration file
    config = 
       ConfigurationManager.OpenMappedExeConfiguration(
         configFileMap, ConfigurationUserLevel.None);

     // Make changes to the new configuration file. 
     // This is to show that this file is the 
     // one that is used.
     string sectionName = "consoleSection";

     ConsoleSection customSection =
       (ConsoleSection)config.GetSection(sectionName);

     if (customSection == null)
     {
         customSection = new ConsoleSection();
         config.Sections.Add(sectionName, customSection);
     }
     else
         // Change the section configuration values.
         customSection =
             (ConsoleSection)config.GetSection(sectionName);

     customSection.ConsoleElement.BackgroundColor =
         ConsoleColor.Green;
     customSection.ConsoleElement.ForegroundColor =
         ConsoleColor.Red;

     // Save the configuration file.
     config.Save(ConfigurationSaveMode.Modified);

     // Force a reload of the changed section. This 
     // makes the new values available for reading.
     ConfigurationManager.RefreshSection(sectionName);

     // Set console properties using the 
     // configuration values contained in the 
     // new configuration file.
     Console.BackgroundColor =
       customSection.ConsoleElement.BackgroundColor;
     Console.ForegroundColor =
       customSection.ConsoleElement.ForegroundColor;
     Console.Clear();

     Console.WriteLine();
     Console.WriteLine("Using OpenMappedExeConfiguration.");
     Console.WriteLine("Configuration file is: {0}", 
       config.FilePath);
   }

' Access a configuration file using mapping.
' This function uses the OpenMappedExeConfiguration 
' method to access a new configuration file.   
' It also gets the custom ConsoleSection and 
' sets its ConsoleElement BackgroundColor and
' ForegroundColor properties to green and red
' respectively. Then it uses these properties to
' set the console colors.  
Public Shared Sub MapExeConfiguration()

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

    Console.WriteLine(config.FilePath)

    If config Is Nothing Then
        Console.WriteLine( _
        "The configuration file does not exist.")
        Console.WriteLine( _
        "Use OpenExeConfiguration to create file.")
    End If

    ' Create a new configuration file by saving 
    ' the application configuration to a new file.
    Dim appName As String = _
        Environment.GetCommandLineArgs()(0)

    Dim configFile As String = _
        String.Concat(appName, "2.config")
    config.SaveAs(configFile, _
                  ConfigurationSaveMode.Full)

    ' Map the new configuration file.
    Dim configFileMap As New ExeConfigurationFileMap()
    configFileMap.ExeConfigFilename = configFile

    ' Get the mapped configuration file
    config = _
    ConfigurationManager.OpenMappedExeConfiguration( _
        configFileMap, ConfigurationUserLevel.None)

    ' Make changes to the new configuration file. 
    ' This is to show that this file is the 
    ' one that is used.
    Dim sectionName As String = "consoleSection"

    Dim customSection As ConsoleSection = _
        DirectCast(config.GetSection(sectionName),  _
            ConsoleSection)

    If customSection Is Nothing Then
        customSection = New ConsoleSection()
        config.Sections.Add(sectionName, customSection)
    End If

    ' Change the section configuration values.
    customSection = _
        DirectCast(config.GetSection(sectionName),  _
            ConsoleSection)
    customSection.ConsoleElement.BackgroundColor = _
        ConsoleColor.Green
    customSection.ConsoleElement.ForegroundColor = _
        ConsoleColor.Red
    ' Save the configuration file.
    config.Save(ConfigurationSaveMode.Modified)

    ' Force a reload of the changed section. This 
    ' makes the new values available for reading.
    ConfigurationManager.RefreshSection(sectionName)

    ' Set console properties using the 
    ' configuration values contained in the 
    ' new configuration file.
    Console.BackgroundColor = _
        customSection.ConsoleElement.BackgroundColor
    Console.ForegroundColor = _
        customSection.ConsoleElement.ForegroundColor
    Console.Clear()

    Console.WriteLine()
    Console.WriteLine( _
        "Using OpenMappedExeConfiguration.")
    Console.WriteLine( _
        "Configuration file is: {0}", config.FilePath)
End Sub

설명

개체는 ConfigurationUserLevel 열려 있는 구성 파일의 위치를 결정합니다. 파일에 없는 사용자 수준이 (구성 파일에 애플리케이션과 동일한 디렉터리)에 있는지 여부를 나타냅니다. 사용자별 수준이 나 (애플리케이션 설정 경로 기준에서 구성 파일은 userLevel).

참고

리소스에 대한 개체를 Configuration 가져오려면 코드에 설정을 상속하는 모든 구성 파일에 대한 읽기 권한이 있어야 합니다. 구성 파일을 업데이트하려면 코드에 구성 파일과 구성 파일이 있는 디렉터리 모두에 대한 쓰기 권한이 추가로 있어야 합니다.

추가 정보

적용 대상

OpenMappedExeConfiguration(ExeConfigurationFileMap, ConfigurationUserLevel, Boolean)

Source:
ConfigurationManager.cs
Source:
ConfigurationManager.cs
Source:
ConfigurationManager.cs

지정된 파일 매핑, 사용자 수준 및 미리 로드 옵션을 사용하여 지정된 클라이언트 구성 파일을 Configuration 개체로 엽니다.

public:
 static System::Configuration::Configuration ^ OpenMappedExeConfiguration(System::Configuration::ExeConfigurationFileMap ^ fileMap, System::Configuration::ConfigurationUserLevel userLevel, bool preLoad);
public static System.Configuration.Configuration OpenMappedExeConfiguration (System.Configuration.ExeConfigurationFileMap fileMap, System.Configuration.ConfigurationUserLevel userLevel, bool preLoad);
static member OpenMappedExeConfiguration : System.Configuration.ExeConfigurationFileMap * System.Configuration.ConfigurationUserLevel * bool -> System.Configuration.Configuration
Public Shared Function OpenMappedExeConfiguration (fileMap As ExeConfigurationFileMap, userLevel As ConfigurationUserLevel, preLoad As Boolean) As Configuration

매개 변수

fileMap
ExeConfigurationFileMap

기본 애플리케이션 구성 파일 대신 사용할 구성 파일입니다.

userLevel
ConfigurationUserLevel

구성을 열 사용자 수준을 지정하는 열거형 값 중 하나입니다.

preLoad
Boolean

모든 섹션 그룹 및 섹션을 미리 로드하려면 true이고, 그렇지 않으면 false입니다.

반환

구성 개체입니다.

예외

구성 파일을 로드할 수 없는 경우

설명

개체는 ConfigurationUserLevel 열려 있는 구성 파일의 위치를 결정합니다. 파일에 없는 사용자 수준이 (구성 파일에 애플리케이션과 동일한 디렉터리)에 있는지 여부를 나타냅니다. 사용자별 수준이 나 (의해 결정 되는 애플리케이션 설정 경로에서 구성 파일은 userLevel).

참고

리소스에 대한 개체를 Configuration 가져오려면 코드에 설정을 상속하는 모든 구성 파일에 대한 읽기 권한이 있어야 합니다. 구성 파일을 업데이트하려면 코드에 구성 파일과 구성 파일이 있는 디렉터리 모두에 대한 쓰기 권한이 추가로 있어야 합니다.

코드 예제는 오버로드를 OpenMappedExeConfiguration 참조하세요.

적용 대상