Sharepoint 2010 无法删除SharePoint 2010 ContentType“;正在使用的内容类型。”;

Sharepoint 2010 无法删除SharePoint 2010 ContentType“;正在使用的内容类型。”;,sharepoint-2010,content-type,Sharepoint 2010,Content Type,我在网上尝试了所有的建议,但都没有用 我按照以下说明编写了一个控制台应用程序: “Usages.Count”为=0。然而,当它试图删除内容类型时,我得到一个异常: “内容类型正在使用中。” 这是一个全新的(开发)安装。我在SP Designer中创建了一个测试站点,创建了一个内容类型,然后创建了一个列表。然后,我删除了列表,将其从回收站中删除,并尝试删除内容类型。。。。。。啊。我对这个问题很失望,直到我找到你的评论。非常好的建议 从站点回收站删除 从网站集>网站设置>网站集管理>回收站删除 从最

我在网上尝试了所有的建议,但都没有用

我按照以下说明编写了一个控制台应用程序:

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

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


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

我对这个问题很失望,直到我找到你的评论。非常好的建议

  • 从站点回收站删除
  • 从网站集>网站设置>网站集管理>回收站删除
  • 从最终用户回收站中删除项目
  • 从“从最终用户回收站删除”中删除
  • 这是大量的回收利用!完成后,我可以删除内容类型

     
    
        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();
              }
           }
        }
    
    
    使用上述代码创建控制台应用程序并运行该项目。这段代码将告诉您内容类型附加在哪些库中。然后简单地转到库并删除附加的内容类型。然后最后从站点操作->站点设置->站点内容类型删除内容类型,或者您也可以使用上述代码删除内容类型

     
    
        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();
              }
           }
        }
    
    
    这对我有用,希望它也对你有用!!!
    谢谢。

    此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()
    

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

    我发现了问题。我一直在读关于“两个”回收站的书。我一直在检查网站和“网站收藏”回收站。我错过了父站点“回收站”顶部标有“网站集回收站”的“链接”。单击该选项(然后选择“从最终用户回收站删除”)后,我能够删除内容类型。感谢您为我节省了6个多小时的沮丧。无法使其工作,但现在我知道了网站收集回收站和网站收集级别的最终用户回收站!您可以在SharePoint SE上的中找到其他原因。;)当我有一个网站内容类型,即使我看到它被清空了所有各级的回收站,它也不会被删除时,这对我来说是有效的。在删除了所有的回收站之后,我仍然无法从UINice中删除它,我忘记了在某些子网站上使用的CT,代码向我指出了它。只需添加一点:for each中的消息应将$ctuse.Url括在$()中,以显示使用CT的Url:
    $($ctuse.Url)
    大家都知道,上面的(C#)代码只是我在OP中提到的代码(包括的Url)的“复制/粘贴”。)
     
    
        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();
              }
           }
        }