How to delete SharePoint On Premise MySite?

Will 616 Reputation points
2020-08-14T05:13:02.65+00:00

Hi there,

Is it possible to remove (delete) particular personal site (SharePoint On Premise) by using CSOM?

Thanks

SharePoint Server Development
SharePoint Server Development
SharePoint Server: A family of Microsoft on-premises document management and storage systems.Development: The process of researching, productizing, and refining new or existing technologies.
1,605 questions
{count} votes

2 answers

Sort by: Most helpful
  1. Amos Wu-MSFT 4,051 Reputation points
    2020-08-14T07:11:28.88+00:00

    As far as I know, if you want to delete top-level site, you need to delete site collection, and SharePoint 2013 on premise CSOM can't provide a method to achieve it.MySite is a top-level site,so you could not delete it with CSOM.
    Test result:
    17628-image.png
    More reference:
    https://social.msdn.microsoft.com/Forums/SharePoint/en-US/bec41d45-56e7-4529-a5f8-f9b594842d36/cannot-delete-toplevel-site?forum=sharepointdevelopment

    0 comments No comments

  2. Will 616 Reputation points
    2020-09-14T08:25:28.14+00:00

    Hi AmosWu,

    I use the following code to delete my site:

    SPWebApplication sPWebApplication = SPWebApplication.Lookup(new Uri(uriAddress));
    SPFieldUrlValue _sp_Personal_Site_Location = new SPFieldUrlValue(properties.ListItem["sp_Personal_Site_Location"].ToString().Trim());

    sPWebApplication.Sites.Delete(_sp_Personal_Site_Location.Description);
    sPWebApplication.Update();

    thanks


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.