Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
Creates an SPWeb object with the specified website-relative URL.
Namespace: Microsoft.SharePoint
Assembly: Microsoft.SharePoint (in Microsoft.SharePoint.dll)
'Declaration
Public Function Add ( _
strWebUrl As String _
) As SPWeb
'Usage
Dim instance As SPWebCollection
Dim strWebUrl As String
Dim returnValue As SPWeb
returnValue = instance.Add(strWebUrl)
public SPWeb Add(
string strWebUrl
)
strWebUrl
Type: System.StringA 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").
Type: Microsoft.SharePoint.SPWeb
An SPWeb object that represents the website.
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();
Note
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.