38

I have tried all the recommendations on the web, to no avail.

I wrote a console application per these instructions: http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.spcontenttypecollection.delete.aspx

The "Usages.Count" is = 0. Yet, when it tries to delete the Content Type I get an Exception:

"The content type is in use."

This is a brand new (development) install. I created a test site in SP Designer, created a Content Type,then a list. Then, I removed the list, removed it from Recycle Bin and tried to remove the content type...... Ugh.

John Saunders
  • 157,405
  • 24
  • 229
  • 388
Shayne
  • 1,033
  • 3
  • 16
  • 29
  • 6
    I found the problem. I kept reading about "two" recycle BINS. I kept checking the site and the "site collection" recycle bins. I missed the "link" at the top of the parent sites "Recycle BIN" labeled "Site Collection Recycle Bin". After clicking on that option (and then selecting "Deleted from end user Recycle Bin") I was able to remove the Content Types. – Shayne Jun 21 '11 at 15:51

4 Answers4

74

I was frustrated by this issue until I found your comment. Excellent advice.

  1. Delete from site recycle bin.
  2. Delete from Site Collection > Site Settings > Site Collection Administration > Recycle Bin.
  3. Delete from End User Recycle Bin Items.
  4. Delete from "Deleted From End User Recycle Bin."

That's a lot of recycling! Once complete, I was able to delete the content type.

Erik Madsen
  • 764
  • 6
  • 4
  • 6
    Thanks for saving me 6 more hours of frustration. – skaz Jul 14 '11 at 13:18
  • 3
    Couldn't get it to work, but now I know about the site collect recycle bin and the end user recycle bin at the site collection level! – barrypicker Jul 18 '14 at 22:01
  • You can find additional causes in [My Answer](https://sharepoint.stackexchange.com/a/233241/44163) on the SharePoint SE. ;) – Chiramisu Jan 06 '18 at 08:22
8

In addition to the recycling bins there's also the page called "Manage files which have no checked in version" under "Permissions and Management" on document libraries - the files in there can also prevent deletion of a content type.

Leak
  • 156
  • 1
  • 5
6

this powershell script form this post also worked for me

$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()
dns_nx
  • 2,971
  • 3
  • 25
  • 52
Mahmoud Farahat
  • 4,777
  • 4
  • 38
  • 57
  • 1
    This worked for me when I had a site content type that would not delete even when I saw it was emptied out of all the recycle bins at every level. – Alan M Dec 13 '14 at 01:02
  • This worked for me after deleting all the recycle bins and I still could not delete it from the UI – Vivek Ayer Jul 25 '16 at 08:27
  • 1
    Nice one, I had forgotten the CT in use on some subsite and the code pinpointed it to me. Just adding a little bit: The message inside the for-each should enclose $ctuse.Url in $() to show the URL where the CT is in use: `$($ctuse.Url)` – GBU Aug 22 '16 at 20:15
0
  

    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();
          }
       }
    }

 

Create a Console Application with the above code and run that project. This code will tell you the libraries in which the content types are attached. Then simply go that libraries and delete the attached content types. Then finally delete the content type from Site Actions -> Site Settings -> Site Content Types or you may use the above code as well to delete the content type.

This worked for me hope it may also work for you !!! Thanks.

Zakir HC
  • 252
  • 1
  • 4
  • 18
  • Just so everyone knows, the (C#) code above is just a "copy/paste" of the one I mentioned (and included the URL for) in the OP. :) – Shayne Sep 28 '16 at 20:12