1

I want to delete Site collection with all sub-sites using CSOM on SharePoint 2013 On-Prem. I've tried with web.DeleteObject() but its works only for sub-sites not for top level site. Pls let me know if there is any other to achieve this way by using CSOM.

1
  • You can indeed delete Site Collections via csom. However, if the Site Collections have existing sub Sites, you may see an error.
    – Dave Smith
    Nov 29, 2017 at 16:35

2 Answers 2

0

you cannot delete Site Collection using CSOM and you will have to rely on either PowerShell or Web Services. you can do it in on SharePoint-Online.

The account that accesses this Web service must be a member of the Farm Administrators group in the Central Administration site. By default, the server's local Administrators group is in the Farm Administrators group. To access the Admin service and its methods, set a Web reference to http://Server_Name:Port_Number/_vti_adm/Admin.asmx.

Source: Link

0

This works in SharePoint 2016

var ctx = new ClientContextWrapper(targetUrl);
var tenant = new Tenant(ctx);
var spoOperation = tenant.RemoveSite(targetUrl);
ctx.Load(spoOperation);
ctx.ExecuteQuery();

If you're in 2013, you may need some extra PowerShell steps to configure your farm - https://blogs.msdn.microsoft.com/vesku/2014/06/09/provisioning-site-collections-using-sp-app-model-in-on-premises-with-just-csom/

https://stackoverflow.com/questions/29665774/remove-site-collection-in-sharepoint-2013-using-csom#30242675

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.