Вопрос

Is there any way to get all the deleted site collections in SharePoint online using CSOM C# / PNP C# ?. In power shell it is possible, but I am looking in c#.

Thanks in advance...

Это было полезно?

Решение

You can use GetDeletedSitePropertiesFromSharePoint from the tenant object.

Try with the below sample code:

string userName = "user@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);

    var deletedSites = tenant.GetDeletedSitePropertiesFromSharePoint("0");
    clientContext.Load(deletedSites, c => c.IncludeWithDefaultProperties(s => s.Url, s => s.SiteId, s => s.DaysRemaining, s => s.Status));
    clientContext.ExecuteQueryRetry();
    // loop through sites 
    // foreach(var site in deletedSites)
    // { }
}

Reference - Tenant.GetDeletedSitePropertiesFromSharePoint method

Лицензировано под: CC-BY-SA с атрибуция
Не связан с sharepoint.stackexchange
scroll top