【问题标题】:Unable to delete SharePoint 2010 ContentType "Contenty type in use."无法删除 SharePoint 2010 内容类型“正在使用的内容类型”。
【发布时间】:2011-09-19 14:48:34
【问题描述】:

我已经尝试了网络上的所有建议,但无济于事。

我根据这些说明编写了一个控制台应用程序:http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.spcontenttypecollection.delete.aspx

“Usages.Count”= 0。然而,当它尝试删除内容类型时,我得到一个异常:

“内容类型正在使用中。”

这是一个全新的(开发)安装。我在 SP Designer 中创建了一个测试站点,创建了一个内容类型,然后创建了一个列表。然后,我删除了列表,将其从回收站中删除并尝试删除内容类型......呃。

【问题讨论】:

  • 我发现了问题。我一直在阅读有关“两个”回收站的信息。我一直在检查网站和“网站收藏”回收站。我错过了标有“站点集合回收站”的父站点“回收站”顶部的“链接”。单击该选项后(然后选择“从最终用户回收站中删除”),我能够删除内容类型。

标签: sharepoint-2010 content-type


【解决方案1】:

在找到您的评论之前,我对这个问题感到很沮丧。很好的建议。

  1. 从网站回收站中删除。
  2. 从网站集删除 > 网站设置 > 网站集管理 > 回收站。
  3. 从最终用户回收站项目中删除。
  4. 从“已从最终用户回收站删除”中删除。

回收量很大!完成后,我就可以删除内容类型了。

【讨论】:

  • 感谢您为我节省了 6 个多小时的挫败感。
  • 无法让它工作,但现在我知道网站集回收站和网站集级别的最终用户回收站!
  • 您可以在 SharePoint SE 上的 My Answer 中找到其他原因。 ;)
【解决方案2】:
  

    using System;
    using System.Collections.Generic;
    using Microsoft.SharePoint;

    namespace Test
    {
       class ConsoleApp
       {
          static void Main(string[] args)
          {
             using (SPSite siteCollection = new SPSite("http://localhost"))
             {
                using (SPWeb webSite = siteCollection.OpenWeb())
                {
                   // Get the obsolete content type.
                   SPContentType obsolete = webSite.ContentTypes["Test"];

                   // We have a content type.
                   if (obsolete != null) 
                   {
                      IList usages = SPContentTypeUsage.GetUsages(obsolete);

                      // It is in use.
                      if (usages.Count > 0) 
                      {
                         Console.WriteLine("The content type is in use in the following locations:");
                         foreach (SPContentTypeUsage usage in usages)
                            Console.WriteLine(usage.Url);
                      }

                      // The content type is not in use.
                      else 
                      {

                         // Delete it.
                         Console.WriteLine("Deleting content type {0}...", obsolete.Name);
                         webSite.ContentTypes.Delete(obsolete.Id);
                      }
                   }

                   // No content type found.
                   else 
                   {
                      Console.WriteLine("The content type does not exist in this site collection.");
                   }
                }
             }
             Console.Write("\nPress ENTER to continue...");
             Console.ReadLine();
          }
       }
    }

 

使用上述代码创建一个控制台应用程序并运行该项目。此代码将告诉您附加内容类型的库。然后只需转到该库并删除附加的内容类型。然后最后从站点操作 -> 站点设置 -> 站点内容类型中删除内容类型,或者您也可以使用上面的代码来删除内容类型。

这对我有用,希望它也对你有用!!! 谢谢。

【讨论】:

  • 大家都知道,上面的 (C#) 代码只是我在 OP 中提到的代码(并包含其 URL)的“复制/粘贴”。 :)
【解决方案3】:

这个post 的powershell 脚本也适用于我

$siteURL = "The Site url"
$contentType = "Content type Name"

$web = Get-SPWeb $siteURL
$ct = $web.ContentTypes[$contentType]

if ($ct) {
$ctusage = [Microsoft.SharePoint.SPContentTypeUsage]::GetUsages($ct)
      foreach ($ctuse in $ctusage) {
        $list = $web.GetList($ctuse.Url)
        $contentTypeCollection = $list.ContentTypes;
        $contentTypeCollection.Delete($contentTypeCollection[$contentType].Id);
        Write-host "Deleted $contentType content type from $ctuse.Url"
        }
$ct.Delete()
Write-host "Deleted $contentType from site."

} else { Write-host "Nothing to delete." }

$web.Dispose()

【讨论】:

  • 当我有一个网站内容类型,即使我看到它已从各个级别的所有回收站中清空,也不会删除,这对我有用。
  • 删除所有回收站后这对我有用,但我仍然无法从 UI 中删除它
  • 不错,我忘记了在某些子站点上使用的 CT,并且代码将其精确定位给了我。只需添加一点:for-each 中的消息应将 $ctuse.Url 包含在 $() 中以显示正在使用 CT 的 URL:$($ctuse.Url)
【解决方案4】:

除了回收站之外,文档库的“权限和管理”下还有一个名为“管理没有签入版本的文件”的页面——其中的文件还可以防止删除内容类型。

【讨论】:

    猜你喜欢
    • 2010-11-12
    • 2012-01-09
    • 1970-01-01
    • 2011-09-08
    • 1970-01-01
    • 1970-01-01
    • 2010-12-01
    • 2016-04-15
    • 1970-01-01
    相关资源
    最近更新 更多