SPWeb.Delete Method
Deletes the website.
Namespace: Microsoft.SharePoint
Assembly: Microsoft.SharePoint (in Microsoft.SharePoint.dll)
Available in Sandboxed Solutions: Yes
Available in SharePoint Online
Syntax
'Declaration
<ClientCallableExceptionConstraintAttribute(FixedId := "SPException$-2146232832", ErrorType := GetType(SPException), _
Condition := "The current site is the top level site.", ErrorCode := )> _
<ClientCallableMethodAttribute(Name := "DeleteObject", RemoveThisObjectFromParentCollection := True)> _
Public Sub Delete
'Usage
Dim instance As SPWeb
instance.Delete()
[ClientCallableExceptionConstraintAttribute(FixedId = "SPException$-2146232832", ErrorType = typeof(SPException),
Condition = "The current site is the top level site.", ErrorCode = )]
[ClientCallableMethodAttribute(Name = "DeleteObject", RemoveThisObjectFromParentCollection = true)]
public void Delete()
Exceptions
Exception | Condition |
---|---|
SPException | The deleting website is a root website. |
Remarks
To delete a site collection, use the Delete method.
Examples
The following code example deletes a specified website.
Using siteCollection As New SPSite("https://localhost")
Dim webSite As SPWeb = siteCollection.AllWebs("DeleteWebSite")
webSite.Delete()
End Using
using (SPSite oSiteCollection = new SPSite("http://Site_Name"))
{
SPWeb oWebsite = oSiteCollection.AllWebs["DeleteWebSite"];
oWebsite.Delete();
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.