共用方式為


ConfigurationUserLevel 列舉

定義

用於指定哪個組態檔要由 Configuration 物件來表示。

public enum class ConfigurationUserLevel
public enum ConfigurationUserLevel
type ConfigurationUserLevel = 
Public Enum ConfigurationUserLevel
繼承
ConfigurationUserLevel

欄位

None 0

取得套用至所有使用者的 Configuration

PerUserRoaming 10

取得套用至目前使用者的漫遊 Configuration

PerUserRoamingAndLocal 20

取得套用至目前使用者的本機 Configuration

範例

下列範例示範如何使用 ConfigurationUserLevel 列舉。


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 來指定要由 和 WebConfigurationManager.OpenMachineConfigurationConfigurationManager.OpenExeConfiguration傳回的 Configuration 物件表示的組態檔。

應用程式組態檔位於與應用程式相同的目錄中,而且具有相同的名稱,但擴展名為 .config。 例如,C:\System\Public.exe 的組態檔 C:\System\Public.exe.config。

應用程式會使用套用至所有使用者的全域組態、套用至個別使用者的個別組態,以及套用至漫遊用戶的設定。

適用於

另請參閱