Quantcast
Channel: SharePoint 2013 - Development and Programming forum
Viewing all articles
Browse latest Browse all 7589

Unable to delete Site collection programmarically

$
0
0

HI

I am facing very weird issue about deleting site collection but before that I will just explain

I want a user having manage webpermission to delete the top level site so I gave the user that permission and the delete link was visible for the user but when user tries to delete then he gets access denied issue.Normally the conclusion was that full control user cannot delete the top level site.

So I created custom action where I redirected to the custom application page which was similar to deleteweb.aspx and wrote code behind for that but still that is not working.

Following is the code.I have tried all options web.delete site.delete  everything but I always get some error.

When I try to use site.Delete() or webApp.sites.Delete then I get "Security validation for this page is invalid".I can't understand why this error is coming.Even I have added form digest control on the application page.

Please let me know how to go forward

 SPSecurity.RunWithElevatedPrivileges(delegate()
                {
                    SPSite nSite = new SPSite(site.ID);
                    SPWeb web = nSite.OpenWeb();
                    web.AllowUnsafeUpdates = true;
                    //web.Delete();
                  //  nSite.AllowUnsafeUpdates = true;
                    SPWebApplication webapp = nSite.WebApplication;
                    SPSiteCollection siteCollection = webapp.Sites;
                    siteCollection.Delete(nSite.Url, false, true);
                    ////snSite.Delete();

                });


Viewing all articles
Browse latest Browse all 7589

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>