本文整理汇总了C#中Tenant.RemoveSite方法的典型用法代码示例。如果您正苦于以下问题:C# Tenant.RemoveSite方法的具体用法?C# Tenant.RemoveSite怎么用?C# Tenant.RemoveSite使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Tenant
的用法示例。
在下文中一共展示了Tenant.RemoveSite方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: DeleteSite
/// <summary>
/// Delete the SiteCollection at the given Uri, also removes it from the recycle bin.
/// Checks whether the site exists before deletion.
/// </summary>
/// <param name="siteUrl"><see cref="Uri"/> of the site to delete</param>
public void DeleteSite(Uri siteUrl)
{
if (siteUrl == null) throw new ArgumentNullException("siteUrl");
var tenant = new Tenant(_client);
string siteToRemoveUrl = siteUrl.ToString().ToLowerInvariant();
// Check whether the site exists.
SPOSitePropertiesEnumerable sitePropEnumerable = tenant.GetSiteProperties(0, true);
_client.Load(sitePropEnumerable);
_client.ExecuteQuery();
bool siteExists = Enumerable.Any(sitePropEnumerable,
property => property.Url.ToLowerInvariant() == siteToRemoveUrl);
if (siteExists)
{
SpoOperation spo = tenant.RemoveSite(siteUrl.ToString());
ExecuteAndWaitForCompletion(tenant, spo);
spo = tenant.RemoveDeletedSite(siteUrl.ToString());
ExecuteAndWaitForCompletion(tenant, spo);
}
}
示例2: DeleteSiteCollectionTenant
/// <summary>
/// Deletes a site collection
/// </summary>
/// <param name="web">Site to be processed - can be root web or sub site</param>
/// <param name="siteUrl">Url of the site collection to delete</param>
/// <param name="useRecycleBin">Leave the deleted site collection in the site collection recycle bin</param>
/// <returns>True if deleted</returns>
public static bool DeleteSiteCollectionTenant(this Web web, string siteUrl, bool useRecycleBin)
{
bool ret = false;
Tenant tenant = new Tenant(web.Context);
SpoOperation op = tenant.RemoveSite(siteUrl);
web.Context.Load(tenant);
web.Context.Load(op, i => i.IsComplete, i => i.PollingInterval);
web.Context.ExecuteQuery();
//check if site creation operation is complete
while (!op.IsComplete)
{
System.Threading.Thread.Sleep(op.PollingInterval);
op.RefreshLoad();
if (!op.IsComplete)
{
try
{
web.Context.ExecuteQuery();
}
catch (WebException webEx)
{
// Context connection gets closed after action completed.
// Calling ExecuteQuery again returns an error which can be ignored
LoggingUtility.LogWarning(MSG_CONTEXT_CLOSED, webEx, EventCategory.Site);
}
}
}
if (useRecycleBin)
{
return true;
}
// To delete Site collection completely, (may take a longer time)
op = tenant.RemoveDeletedSite(siteUrl);
web.Context.Load(op, i => i.IsComplete, i => i.PollingInterval);
web.Context.ExecuteQuery();
while (!op.IsComplete)
{
System.Threading.Thread.Sleep(op.PollingInterval);
op.RefreshLoad();
if (!op.IsComplete)
{
try
{
web.Context.ExecuteQuery();
}
catch (WebException webEx)
{
// Context connection gets closed after action completed.
// Calling ExecuteQuery again returns an error which can be ignored
LoggingUtility.LogWarning(MSG_CONTEXT_CLOSED, webEx, EventCategory.Site);
}
}
}
ret = true;
return ret;
}
示例3: DeleteSiteCollection
/// <summary>
/// Method for deleting site collections
/// </summary>
/// <param name="clientContext">SharePoint Client Context</param>
/// <param name="clientUrl">Url for Site Collection</param>
internal static void DeleteSiteCollection(ClientContext clientContext, string clientUrl)
{
try
{
Tenant tenant = new Tenant(clientContext);
clientContext.Load(tenant);
clientContext.ExecuteQuery(); //login into SharePoint online
SPOSitePropertiesEnumerable spSiteProperties = tenant.GetSiteProperties(0, true);
clientContext.Load(spSiteProperties);
clientContext.ExecuteQuery();
SiteProperties siteProperties = (from properties in spSiteProperties
where properties.Url.ToString().ToUpper() == clientUrl.ToUpper()
select properties).FirstOrDefault();
if (null != siteProperties)
{
// site exists
// delete the site
SpoOperation spoOperation = tenant.RemoveSite(clientUrl);
clientContext.Load(spoOperation, operation => operation.IsComplete);
clientContext.ExecuteQuery();
while (!spoOperation.IsComplete)
{
Console.Write(".");
//Wait for 30 seconds and then try again
System.Threading.Thread.Sleep(30000);
spoOperation.RefreshLoad();
clientContext.ExecuteQuery();
}
Console.WriteLine("Site Collection: " + clientUrl + " is deleted successfully");
}
else
{
// site does not exists
return;
}
}
catch (Exception exception)
{
Console.WriteLine("Exception occurred while deleting site collection: " + exception.Message);
}
}