Friday, November 6, 2009

How To Delete an “Orphan” Content Type?

Problem

I created a set of content types from a feature and after the installation, activation of this feature, I used (in list or document libraries) all content types contained in this feature but one, called CT1 for instance

After a while, I wanted to remove the never used content type, so I modified the feature, removed the content type CT1 from it, reinstalled the feature.

The content type CT1 was still in the content types list! Ok, no problem, from the UI I click on delete this content type, and…

image

The content type "CT1" is part of an application feature.

What a message! I removed it from the feature, but still, I have this error. I googled a lot and with the help of Vincent Rothwell I finally found a solution, not Microsoft allowed, but efficient!

Solution

First, I checked if the content type was not used somewhere in a site (see Vincent Rothwell article)

Then I went to the DB and in the ContentTypes table, you can filter the CT you want with:

SELECT [SiteId]
      ,[Class]
      ,[Scope]
      ,sys.fn_varbintohexstr([ContentTypeId]) as CT
      ,[Version]
      ,[NextChildByte]
      ,[Size]
      ,[Definition]
      ,[ResourceDir]
      ,[IsFromFeature]
  FROM [SharePoint - 27235].[dbo].[ContentTypes]
where (sys.fn_varbintohexstr(ContentTypeId) LIKE '0x0101EF0201%')

Because I defined the CT, I knew the ContentTypeId. And I used sys.fn_varbintohexstr() because the ContentTypeId is of type tContentTypeId which is a varbinary(512)

In the result, you can see the column IsFromFeature set to 1. This means your CT belongs to a feature
image So one solution was to change the value of IsFromFeature to 0, in order to “fake” SharePoint.

Update [SharePoint - 27235].[dbo].[ContentTypes] set [IsFromFeature] = 0 where (sys.fn_varbintohexstr(ContentTypeId) LIKE '0x0101EF0201%')

Then I could delete the content type CT1 directly from the UI!