Creates a Web site object with the specified Web site-relative URL.
Namespace: Microsoft.SharePoint
Assembly: Microsoft.SharePoint (in microsoft.sharepoint.dll)
Visual Basic (Declaration)
Public Function Add ( _
strWebUrl As String _
) As SPWeb
Dim instance As SPWebCollection
Dim strWebUrl As String
Dim returnValue As SPWeb
returnValue = instance.Add(strWebUrl)
public SPWeb Add (
string strWebUrl
)
Parameters
- strWebUrl
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
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")
mySite.Dispose()
SPSite oSiteCollection = SPContext.Current.Site;
SPWebCollection collWebsites = oSiteCollection.AllWebs;
SPWeb oWebsite = collWebsites.Add("Website/Subsite/MyNewSubsite");
oWebsite.Dispose();