ConfigurationUserLevel Enum
Definitie
Belangrijk
Bepaalde informatie heeft betrekking op een voorlopige productversie die aanzienlijk kan worden gewijzigd voordat deze wordt uitgebracht. Microsoft biedt geen enkele expliciete of impliciete garanties met betrekking tot de informatie die hier wordt verstrekt.
Wordt gebruikt om op te geven welk configuratiebestand moet worden vertegenwoordigd door het configuratieobject.
public enum class ConfigurationUserLevel
public enum ConfigurationUserLevel
type ConfigurationUserLevel =
Public Enum ConfigurationUserLevel
- Overname
Velden
| Name | Waarde | Description |
|---|---|---|
| None | 0 | Hiermee haalt u de Configuration gegevens op die van toepassing zijn op alle gebruikers. |
| PerUserRoaming | 10 | Hiermee haalt u de roaming Configuration op die van toepassing is op de huidige gebruiker. |
| PerUserRoamingAndLocal | 20 | Hiermee haalt u de lokale Configuration op die van toepassing is op de huidige gebruiker. |
Voorbeelden
In het volgende voorbeeld ziet u hoe u de ConfigurationUserLevel opsomming gebruikt.
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
Opmerkingen
Gebruik ConfigurationUserLevel dit om op te geven welk configuratiebestand moet worden vertegenwoordigd door het configuratieobject dat wordt geretourneerd door ConfigurationManager.OpenExeConfiguration en WebConfigurationManager.OpenMachineConfiguration.
Toepassingsconfiguratiebestanden bevinden zich in dezelfde map als de toepassing en hebben dezelfde naam, maar met een .config extensie. Het configuratiebestand voor C:\System\Public.exe is bijvoorbeeld C:\System\Public.exe.config.
Toepassingen gebruiken een globale configuratie die van toepassing is op alle gebruikers, afzonderlijke configuraties die van toepassing zijn op afzonderlijke gebruikers en configuraties die van toepassing zijn op zwervende gebruikers.