5

I created a content type to play around with. I created a publishing page based on this content type, but after deleting the page (and clearing the recycling bin) SharePoint won't let me delete it.

The content type is in use.

After some investigation, I ran the following PowerShell code which would tell me where the content type is being used.

$site = Get-SPSite("http://mySite");
foreach ($web in $site.AllWebs) {
   $ctype = $web.ContentTypes["Test-publishing-page-parent"]
   $usages = [Microsoft.Sharepoint.SPContentTypeUsage]::GetUsages($ctype)
   foreach ($usage in $usages) {
      Write-Host $usage.Url
   }
}

The output was /Pages

There are no more pages that exist in the Pages collection (or the recylcing bin) that reference the content type.

enter image description here

However, I did notice that the "New Document" selection drop down contains references to this content type (and others!). In fact, it seems that I cannot delete any custom content types that are referenced in this selection drop down, even though they are not used anywhere else. Any ideas? Is this a possible bug in SharePoint 2013?

enter image description here

Note: Yes, I've already cleared the recycling bin several times, at the site level and the site collection level.

SharePoint 2013 on-premise.

3 Answers 3

5

The content type was added to the available content types for your Pages Library. Go to Pages > Library ribbon > Library settings > Content types section. Click on the content type name there and then delete.

That will remove it from the Pages library. Then you can go into Site Settings > Content Types and delete it there.

1
  • You're welcome. I'm going to have to try out that PowerShell it looks useful.
    – Rothrock
    Mar 4, 2015 at 17:27
1

I was able to find the problem and the solution.

It all started when I wanted to create a site template from a subsite. When attempting to use the template, SharePoint threw an error saying that there was a duplicate content type. It was not possible simply to delete the duplicate content type because another error was reported, something like "is still in use".

Faced with a lot of research, delete and restore my lists and some scripts later, I decided to delete all items from the "Tasks" list, which in my case was the list where the content type was associated. After that, I was able to remove it from the list and then permanently delete it from the site.

Well, this was done in a QA environment. I suggest making a back up plan before deleting items and lists.

0

Sometimes you think that because you deleted all items of that content type and removed all references from all lists/document libraries, there are no more references, but you may be forgetting about the recycle bin, and there are two of them: the site and the site collection. These won't show up in the references that you get using the API. You can empty them using the UI or through the API:

SPSecurity.RunWithElevatedPrivileges(() =>
{
    using (var site = new SPSite("https://my.site"))
    {
        var query = new SPRecycleBinQuery();
        //for first-level, site recycle bin, uncomment this line
        //query.ItemState = SPRecycleBinItemState.FirstStageRecycleBin;
        query.ItemState = SPRecycleBinItemState.SecondStageRecycleBin;

        var items = site.GetRecycleBinItems(query);

        foreach (var item in items.OfType<SPRecycleBinItem>())
        {
            item.Delete();
        }
    }
});

After this, you can try deleting the content type programmatically:

SPSecurity.RunWithElevatedPrivileges(() =>
{
    using (var site = new SPSite("https://my.site"))
    {
        var web = site.RootWeb;
        var ctype = web.ContentTypes["MyContentType"];
        ctype.Delete();
    }
});

Hope this helps!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.