WebExtensions.DeleteWeb (PnP Core Component) – This extension method first checks the ahild site is available in the specified url and then delete that child site from the parent web.

Supports: SharePoint 2013+, SharePoint Online

Assembly: OfficeDevPnP.Core.dll
Namespace: Microsoft.SharePoint.Client


bool DeleteWeb(string subsiteUrl)


Parameter Type Description
subsiteUrl string A string that represents the URL leaf name of a subsite
Return Type Description
bool true if the web was deleted; otherwise false if nothing was done


Single Line Code: Web.DeleteWeb(“subsiteurl”)

Code Snippet:

The following example deletes the subsite from the parent website based on the given url and returns true value. If the subsite is not available or problem in deleting the child site, this method returns false.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.SharePoint.Client;
using OfficeDevPnP.Core;

// Assembly Reference Used: OfficeDevPnP.Core, Version=2.4.1605.0, Culture=neutral, PublicKeyToken=3751622786b357c2
namespace SampleApplication
    class Program
        static void Main(string[] args)
            string siteUrl = "https://sharepointonline.sharepoint.com";           

            AuthenticationManager authManager = new AuthenticationManager();
            //Interactive Login to SharePoint site - Opens a Online signin page to authenticate the user
            var context = authManager.GetWebLoginClientContext(siteUrl);
	     //Deletes the child website with the specified subsite URL, from a parent Web, if it exists. Else the method return false value.
            bool success = context.Web.DeleteWeb("subsiteurl");

            if (success)
                Console.WriteLine("Site deleted successfully.");
                Console.WriteLine("Problem in deleting the site.");

            Console.WriteLine("Press any key to exit.");

The above code also available from GitHub