Delete site collection programmatically SharePoint 2013

Delete site collection programmatically SharePoint 2013

Delete site collection programmatically SharePoint 2013. In this post, I describe you to Delete site collection programmatically. It is very rare scenario that we need to Delete site collections programmatically. When we need to Delete site collection in Bulk, then we need to Delete site collection programmatically. It save time.

Code is below that is 100% working:-[AdSense-A]

 

public static void DeleteSiteCollection(string requestUrl, string siteUrl)
        {
            SPSite site = new SPSite(requestUrl);
            SPWeb web = null;
            try
            {
                SPWebApplication webapp = site.WebApplication;
                web = site.OpenWeb();
                SPSiteCollection spSites = webapp.Sites;
                webapp.Sites.Delete(siteUrl);
                string Site = "Site Collection is Deleteted:" + " " + "" + siteUrl + "";
                ReadWriteException.LogFileWrite(Site);
            }
            catch (Exception ex)
            {
                ReadWriteException.LogFileWrite(ex.Message);
                ReadWriteException.LogFileWrite(ex.InnerException.Message);
            }
            finally
            {

            }
        }

 


Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

error: Content is protected !!