首页 > 解决方案 > 如何以编程方式使用 pnp csom 删除 SharePoint 网站集

问题描述

我对 SharePoint Online Office 365 有一个要求。根据我的要求,我必须以编程方式使用 pnp csom 从 SharePoint Online Office 365 管理中心删除所有网站集。

任何人都可以建议我如何删除所有网站集?

标签: sharepointcsom

解决方案


您可以使用DeleteSiteCollection扩展方法来删除网站集。

它可以如下使用:

string userName = "admin@tenant.onmicrosoft.com";
string password = "password";

string siteUrl = "https://tenant-admin.sharepoint.com/";

using (ClientContext clientContext = new ClientContext(siteUrl))
{
    SecureString securePassword = new SecureString();
    foreach (char c in password.ToCharArray())
    {
        securePassword.AppendChar(c);
    }

    clientContext.AuthenticationMode = ClientAuthenticationMode.Default;
    clientContext.Credentials = new SharePointOnlineCredentials(userName, securePassword);

    var tenant = new Tenant(clientContext);

    // use false, if you want to keep site collection in recycle bin
    tenant.DeleteSiteCollection("https://tenant.sharepoint.com/sites/Test", true);

}

推荐阅读