Site.Create Method [IIS 7 and higher]

Creates a new Web site.

Syntax

objAppSrv.Get("Site").Create(
   SiteName,
   Bindings[],
   PhysicalPath,
   ServerAutoStart
)
var newsite = appsrv.Get("Site").Create(
   SiteName,
   Bindings[],
   PhysicalPath,
   ServerAutoStart
);

Parameters

Name

Description

Name

A string that contains the name for the new Web site.

Bindings

An array of BindingElement objects. The binding should include at least one host name, port, or IP address.

PhysicalPath

A string that contains a fully qualified path of a physical directory to which you want the Web site mapped.

ServerAutoStart

An optional boolean value. true if the server instance should start automatically when the World Wide Web Publishing Service (WWW service) is started; otherwise, false.

Return Value

This method does not return a value.

Remarks

This method replaces the IIS 6.0 IIsWebService.CreateWebSite method.

Note

You cannot use Site.SpawnInstance_ and Site.Put_ to create a new Web site. A new site must have a root application and a root virtual directory, and these can be specified only through the Create method.

Example

The following example creates a new Web site.

Note

Because Create is a static method, you must call it by using the Site definition.

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

' Specify a name and physical path for the new Web site.
SiteName = "SampleSite"
PhysicalPath = "C:\inetpub\wwwroot"

' Create a Bindings object by using the WMI SpawnInstance_ method.
Set SiteBinding = oWebAdmin.Get("BindingElement").SpawnInstance_
SiteBinding.BindingInformation = "*:80:www.SampleSite.com"
SiteBinding.Protocol = "http"
BindingsArray = array(SiteBinding)

' Get the site object definition
Set SiteDefinition = oWebAdmin.Get("Site")

' Pass the required parameters to the Create method on the Site
' definition to create the site.
SiteDefinition.Create SiteName, BindingsArray, PhysicalPath

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

BindingElement Class [IIS 7 and higher]

Site Class [IIS 7 and higher]