当前位置: 首页>>代码示例>>C#>>正文


C# Tenant.RemoveSite方法代码示例

本文整理汇总了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);
            }
        }
开发者ID:gavinbarron,项目名称:o365-provisioning-samples,代码行数:29,代码来源:SiteProvisioner.cs

示例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;
        }
开发者ID:BNATENSTEDT,项目名称:PnP,代码行数:68,代码来源:SiteExtensions.cs

示例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);
            }
        }
开发者ID:RMSATS,项目名称:mattercenter,代码行数:50,代码来源:Program.cs


注:本文中的Tenant.RemoveSite方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。