This documentation is archived and is not being maintained.

SPWebCollection.Add Method (String)

Windows SharePoint Services 3

Creates a Web site object with the specified Web site-relative URL.

Namespace:  Microsoft.SharePoint
Assembly:  Microsoft.SharePoint (in Microsoft.SharePoint.dll)

public SPWeb Add(
	string strWebUrl


Type: System.String
A string that contains the new Web site URL relative to the root Web site in the site collection. For example, to create a Web site at http://MyServer/sites/MySiteCollection/MyNewWebsite, specify MyNewWebsite, or to create a Web site one level lower at http://MyServer/sites/MySiteCollection/Website/MyNewWebsite, specify Website/MyNewWebsite.

Return Value

Type: Microsoft.SharePoint.SPWeb
An SPWeb object that represents the Web site.

The following code example creates a Web site within the current site collection.

Dim siteCollection As SPSite = SPControl.GetContextSite(Context)
Dim subSites As SPWebCollection = siteCollection.AllWebs

Dim mySite As SPWeb = subSites.Add("MyNewWebsite")

SPSite oSiteCollection = SPContext.Current.Site;
SPWebCollection collWebsites = oSiteCollection.AllWebs;
SPWeb oWebsite = collWebsites.Add("Website/Subsite/MyNewSubsite");

Certain objects implement the IDisposable interface, and you must avoid retaining these objects in memory after they are no longer needed. For information about good coding practices, see Best Practices: Using Disposable Windows SharePoint Services Objects.