WebConfigurationManager.OpenMachineConfiguration Method ()
.NET Framework (current version)
Opens the machine-configuration file on the current computer as a Configuration object to allow read or write operations.
Assembly: System.Web (in System.Web.dll)
| Exception | Condition |
|---|---|
| ConfigurationErrorsException | A valid configuration file could not be loaded. |
The OpenMachineConfiguration method opens the machine-configuration file on the computer where the application runs. This file is located in the standard build directory %windir%\Microsoft.NET\Framework\version\config.
The following example shows how to access configuration information with the OpenMachineConfiguration method.
// Show how to use OpenMachineConfiguration(). // It gets the machine.config file on the current // machine and displays section information. static void OpenMachineConfiguration1() { // Get the machine.config file on the current machine. System.Configuration.Configuration config = WebConfigurationManager.OpenMachineConfiguration(); // Loop to get the sections. Display basic information. Console.WriteLine("Name, Allow Definition"); int i = 0; foreach (ConfigurationSection section in config.Sections) { Console.WriteLine( section.SectionInformation.Name + "\t" + section.SectionInformation.AllowExeDefinition); i += 1; } Console.WriteLine("[Total number of sections: {0}]", i); // Display machine.config path. Console.WriteLine("[File path: {0}]", config.FilePath); }
.NET Framework
Available since 2.0
Available since 2.0
Show: