Edit

Share via


ConfigurationUserLevel Enum

Definition

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

C#
public enum ConfigurationUserLevel
Inheritance
ConfigurationUserLevel

Fields

Name Value Description
None 0

Gets the Configuration that applies to all users.

PerUserRoaming 10

Gets the roaming Configuration that applies to the current user.

PerUserRoamingAndLocal 20

Gets the local Configuration that applies to the current user.

Examples

The following example shows how to use the ConfigurationUserLevel enumeration.

C#

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();
    }
}

Remarks

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.

Applies to

Product Versions
.NET 8 (package-provided), 9 (package-provided)
.NET Framework 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7 (package-provided), 4.7, 4.7.1 (package-provided), 4.7.1, 4.7.2 (package-provided), 4.7.2, 4.8 (package-provided), 4.8, 4.8.1
.NET Standard 2.0 (package-provided)
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9

See also