SPWebCollection.Add method (String)
Creates an SPWeb object with the specified website-relative URL.
Assembly: Microsoft.SharePoint (in Microsoft.SharePoint.dll)
- Type: System.String
A string that specifies the URL for the new website. If the SPWebCollection object represents the websites within a site collection, the URL is server-relative and begins with a forward slash (for example, "/sites/MySitecollection/MyNewWebSite"). If the SPWebCollection object represents the child websites directly beneath a website, the URL is relative to the website and does not begin with a forward slash (for example, "MyNewWebSite").
The following code example creates a website 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") mySite.Dispose()
SPSite oSiteCollection = SPContext.Current.Site; SPWebCollection collWebsites = oSiteCollection.AllWebs; SPWeb oWebsite = collWebsites.Add("Website/Subsite/MyNewSubsite"); oWebsite.Dispose();
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 Disposing Objects.