Site.Create Method1

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 - IIS 7.0 on Windows Vista
- IIS 7.5 on Windows 7
- IIS 8.0 on Windows 8
- IIS 10.0 on Windows 10
Server - IIS 7.0 on Windows Server 2008
- IIS 7.5 on Windows Server 2008 R2
- IIS 8.0 on Windows Server 2012
- IIS 8.5 on Windows Server 2012 R2
- IIS 10.0 on Windows Server 2016
Product - IIS 7.0, IIS 7.5, IIS 8.0, IIS 8.5, IIS 10.0
MOF file WebAdministration.mof

See Also

BindingElement Class
Site Class