Export (0) Print
Expand All
Expand Minimize

ConfigurationUserLevel Enumeration

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

Namespace:  System.Configuration
Assembly:  System.Configuration (in System.Configuration.dll)

public enum ConfigurationUserLevel

Member nameDescription
NoneGet the Configuration that applies to all users.
PerUserRoamingGet the roaming Configuration that applies to the current user.
PerUserRoamingAndLocalGet the local Configuration that applies to the current user.

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.

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

.NET Framework

Supported in: 4.5, 4, 3.5, 3.0, 2.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Show:
© 2014 Microsoft