Opens the Web-application configuration file as a Configuration object using the specified virtual path to allow read or write operations.
Namespace:
System.Web.Configuration
Assembly:
System.Web (in System.Web.dll)
Visual Basic (Declaration)
Public Shared Function OpenWebConfiguration ( _
path As String _
) As Configuration
Dim path As String
Dim returnValue As Configuration
returnValue = WebConfigurationManager.OpenWebConfiguration(path)
public static Configuration OpenWebConfiguration(
string path
)
public:
static Configuration^ OpenWebConfiguration(
String^ path
)
public static function OpenWebConfiguration(
path : String
) : Configuration
Parameters
- path
- Type: System..::.String
The virtual path to the configuration file. If nullNothingnullptra null reference (Nothing in Visual Basic), the root Web.config file is opened.
To obtain the Configuration object for a resource, your code must have read privileges on all the configuration files from which it inherits settings. To update a configuration file, your code must additionally have write privileges for both the configuration file and the directory in which it exists.
The following example shows how to access configuration information with the OpenWebConfiguration method.
' Show how to use OpenWebConfiguration(string).
' It gets he appSettings section of a Web application
' runnig on the local server.
Shared Sub OpenWebConfiguration1()
' Get the configuration object for a Web application
' running on the local server.
Dim config As System.Configuration.Configuration = _
WebConfigurationManager.OpenWebConfiguration("/configTest")
' Get the appSettings.
Dim appSettings As KeyValueConfigurationCollection = _
config.AppSettings.Settings
' Loop through the collection and
' display the appSettings key, value pairs.
Console.WriteLine("[appSettings for app at: {0}]", "/configTest")
Dim key As String
For Each key In appSettings.AllKeys
Console.WriteLine("Name: {0} Value: {1}", _
key, appSettings(key).Value)
Next key
Console.WriteLine()
End Sub 'OpenWebConfiguration1
// Show how to use OpenWebConfiguration(string).
// It gets he appSettings section of a Web application
// runnig on the local server.
static void OpenWebConfiguration1()
{
// Get the configuration object for a Web application
// running on the local server.
System.Configuration.Configuration config =
WebConfigurationManager.OpenWebConfiguration("/configTest")
as System.Configuration.Configuration;
// Get the appSettings.
KeyValueConfigurationCollection appSettings =
config.AppSettings.Settings;
// Loop through the collection and
// display the appSettings key, value pairs.
Console.WriteLine("[appSettings for app at: {0}]", "/configTest");
foreach (string key in appSettings.AllKeys)
{
Console.WriteLine("Name: {0} Value: {1}",
key, appSettings[key].Value);
}
Console.WriteLine();
}
Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98
The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
.NET Framework
Supported in: 3.5, 3.0, 2.0
Reference