WebConfigurationManager.OpenMachineConfiguration Method ()

 

Opens the machine-configuration file on the current computer as a Configuration object to allow read or write operations.

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

Public Shared Function OpenMachineConfiguration As Configuration

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. 
Shared Sub OpenMachineConfiguration1()
   ' Get the machine.config file on the current machine.
     Dim config As System.Configuration.Configuration = _
     WebConfigurationManager.OpenMachineConfiguration()

   ' Loop to get the sections. Display basic information.
   Console.WriteLine("Name, Allow Definition")
   Dim i As Integer = 0
   Dim section As ConfigurationSection
   For Each section In  config.Sections
         Console.WriteLine((section.SectionInformation.Name + _
         ControlChars.Tab + _
         section.SectionInformation.AllowExeDefinition.ToString()))
         i += 1
     Next section
     Console.WriteLine("[Total number of sections: {0}]", i)

     ' Display machine.config path.
     Console.WriteLine("[File path: {0}]", config.FilePath)
 End Sub 'OpenMachineConfiguration1


.NET Framework
Available since 2.0
Return to top
Show: