VirtualDirectory.Create Method [IIS 7 and higher]

Creates a virtual directory.

Syntax

objAppSrv.Get("VirtualDirectory").Create(
   VirtualDirectoryPath,
   ApplicationPath,
   PhysicalPath,
   SiteName
);
objAppSrv.Get("VirtualDirectory").Create(
   VirtualDirectoryPath,
   ApplicationPath,
   PhysicalPath,
   SiteName
)

Parameters

Name

Description

VirtualDirectoryPath

A string value that contains the virtual directory path (for example, "/MyVDir").

ApplicationPath

A string value that contains the application path (for example, "/MyApp").

PhysicalPath

An optional string value that contains the physical path to the file directory where the content for the virtual directory is stored (for example, "C:\inetpub\MyVDirFiles"). Although this parameter is optional, most implementations will require it.

NoteNote:
IIS does not check for the existence of the specified physical directory. If you specify an invalid path and attempt to open the virtual directory in IIS Manager, IIS Manager will display the error message "Could not find a part of the path '<path>'".

SiteName

A string value that contains the name of the Web site for the virtual directory (for example, "Default Web Site").

Return Value

This method does not return a value.

Remarks

The VirtualDirectory object inherits from the ConfiguredObject class; it does not inherit from the VirtualDirectoryElementDefaults class. This means that the properties on the VirtualDirectoryElementDefaults object must also be declared on the VirtualDirectory object.

Example

The following example creates a virtual directory called MyVDir under the MyApp application on the default Web site.

' Connect to the WebAdministration namespace.
Set oWebAdmin = GetObject("winmgmts:root\WebAdministration")

' Define the parameters.
strVDirPath = "/MyVDir"
strAppPath = "/MyApp"
strPhysicalPath = "C:\inetpub\MyVDirFiles"
strSiteName = "Default Web Site"

' Create the new virtual directory.
oWebAdmin.Get("VirtualDirectory").Create _
    strVDirPath, strAppPath, strPhysicalPath, strSiteName

Requirements

Type

Description

Client

Requires IIS 7 on Windows Vista.

Server

Requires IIS 7 on Windows Server 2008.

Product

IIS 7

MOF file

WebAdministration.mof

See Also

Reference

VirtualDirectory Class [IIS 7 and higher]

VirtualDirectoryContainsConfigurationSection Class [IIS 7 and higher]